close

[Solved] Error: ‘float’ object has no attribute ‘isna'”

Hello Guys, How are you all? Hope You all Are Fine. Today I get the following error Error: ‘float’ object has no attribute ‘isna'” in python. So Here I am Explain to you all the possible solutions here.

Without wasting your time, Let’s start This Article to Solve This Error.

How Error: ‘float’ object has no attribute ‘isna'” Error Occurs?

Today I get the following error Error: ‘float’ object has no attribute ‘isna'” in python.

How To Solve Error: ‘float’ object has no attribute ‘isna'” Error ?

  1. How To Solve Error: 'float' object has no attribute 'isna'” Error ?

    To Solve Error: 'float' object has no attribute 'isna'” Error I on purpose didn't change the original concept of processing the source Series in a loop. It looks like both print instructions are rather “placeholders”, to be replaced with one piece of code for NaN values and another for other values.

  2. Error: 'float' object has no attribute 'isna'”

    To Solve Error: 'float' object has no attribute 'isna'” Error I on purpose didn't change the original concept of processing the source Series in a loop. It looks like both print instructions are rather “placeholders”, to be replaced with one piece of code for NaN values and another for other values.

Solution 1

No need for explicit for loops. Based on your second attempt:

# Setup
my_series = pd.Series([np.nan, np.nan, ['A', 'B']])

# Solution
np.where(my_series.isnull(), 'do A', 'do B')                                              

# Output
array(['do A', 'do A', 'do B'], dtype='<U4')

Solution 2

Change your code to:

for element in my_series:
    if type(element) == float and pd.isna(element):
        print('do A')
    else:
        print('do B')

Edit following the comment by Peter

I on purpose didn’t change the original concept of processing the source Series in a loop. It looks like both print instructions are rather “placeholders”, to be replaced with one piece of code for NaN values and another for other values.

Summery

It’s all About this issue. Hope all solution helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which solution worked for you? Thank You.

Also, Read