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.

Answer from Valdi_Bo on Stack Overflow
🌐
Bobby Hadz
bobbyhadz.com › blog › python-attributeerror-float-object-has-no-attribute
AttributeError: 'float' object has no attribute 'X' (Python) | bobbyhadz
The Python "AttributeError: 'float' object has no attribute" occurs when we try to access an attribute that doesn't exist on a floating-point number, e.g.
Discussions

if np.isnan(grad_norm.cpu()): AttributeError: 'float' object has no attribute 'cpu'
There was an error while loading. Please reload this page · 运行环境:天池实验室notebook gpu https://tianchi.aliyun.com/ https://dsw-dev.data.aliyun.com/ run: !python synthesizer_train.py mandarin /data/nas/workspace/jupyter/data/SV2TTS/synthesizer More on github.com
🌐 github.com
5
October 19, 2021
BUG: np.isna() is working
Describe the issue: I used to find na values from the data frame it used to work till 2 days before but from today as I tested it's not working. I tested in different IDEs that include Google C... More on github.com
🌐 github.com
1
September 20, 2023
I have a problem to check the range and type of the entry values using .get: "AttributeError: 'float' object has no attribute 'get'"
Hi, I expect that the below code build a GUI window and get three parameters from user, check the range of parameter 1 (which should be between 0 and 1), and handle any unacceptable value using a warning message box. However, if the entered value is out of range, the below error appears. More on discuss.python.org
🌐 discuss.python.org
7
0
September 21, 2023
python - float object has no attribute isna - Stack Overflow
I have a df where all columns are objects. Why can't I apply a function that checks whether 2 column have a NaN. I want to avoid np.where since I have has 6 other elif lines in the function. df ... More on stackoverflow.com
🌐 stackoverflow.com
February 17, 2021
🌐
freeCodeCamp
forum.freecodecamp.org › python
Bug found in Data Analysis Example B Lecture File - Python - The freeCodeCamp Forum
July 7, 2022 - In the Lecture_2.ipynb example code is: df['rental_gain_return'].mean().round(2) results in: AttributeError: 'float' object has no attribute 'round' This is incorrect and should be: round(df['rental_gain_return'].mean(),2) Same with the median as well. Version of python: 3.10.5 Version of pandas: ...
🌐
GitHub
github.com › babysor › MockingBird › issues › 160
if np.isnan(grad_norm.cpu()): AttributeError: 'float' object has no attribute 'cpu' · Issue #160 · babysor/MockingBird
October 19, 2021 - Traceback (most recent call last): File "synthesizer_train.py", line 35, in train(**vars(args)) File "/data/nas/workspace/jupyter/MockingBird/synthesizer/train.py", line 200, in train if np.isnan(grad_norm.cpu()): AttributeError: 'float' object has no attribute 'cpu' No one assigned ·
Author   lcp580
🌐
GitHub
github.com › numpy › numpy › issues › 24759
BUG: np.isna() is working · Issue #24759 · numpy/numpy
September 20, 2023 - Describe the issue: I used to find na values from the data frame it used to work till 2 days before but from today as I tested it's not working. I tested in different IDEs that include Google C...
Author   kushal-h
Top answer
1 of 3
2

The first correction: Don't use df as the parameter name in func, because the passed object is a row. Use e.g. row instead.

The second correction is that some cells contain values of string type, which has no isna() method. Use pd.isna() instead, as it works on a source argument of any type.

So define your function e.g. as:

def func(row):
    if pd.isna(row.check1) & pd.isna(row.check2):
        return row.colb
    else:
        return '-'

I added another return for else variant, but I assume that you have a couple of elif ... instructions there.

2 of 3
1

You are applying the isna method to a float object which, as the error states, doesn't have such a method:

>>> import pandas as pd
>>> pd.Series([1, np.nan]).apply(lambda x: x.isna())
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/ubuntu/documents/assets/envs/venv/lib/python3.6/site-packages/pandas/core/series.py", line 4212, in apply
    mapped = lib.map_infer(values, f, convert=convert_dtype)
  File "pandas/_libs/lib.pyx", line 2403, in pandas._libs.lib.map_infer
  File "<stdin>", line 1, in <lambda>
AttributeError: 'float' object has no attribute 'isna'

You could instead use np.isnan to test whether a float is nan, like so:

>>> pd.Series([1, np.nan]).apply(lambda x: True if not np.isnan(x) else False)
0     True
1    False
dtype: bool

So your function would look like this:

def func(df):
    try:
        test = np.isnan(df['check1']) and np.isnan(df['check2'])
    except Exception as e:
        if 'not supported for the input types' in str(e):
            test = False
        else:
            raise
    return df['colb'] if test else df

You might consider using some other variable name for func besides df as apply applies functions row-wise, not necessarily on an entire dataframe.

🌐
CSDN
devpress.csdn.net › python › 630460da7e6682346619ac5c.html
Error: 'float' object has no attribute 'isna' - DevPress官方社区
August 23, 2022 - Answer a question I have the below series: my_series = pd.Series([np.nan, np.nan, ['A', 'B']]) I have to loop through my_series and evaluate whether the value is NaN or not and then do something (acti Mangs Python
Find elsewhere
🌐
Researchdatapod
researchdatapod.com › home › how to solve python attributeerror: ‘numpy.float64’ object has no attribute ‘isna’
How to Solve Python AttributeError: 'numpy.float64' object has no attribute 'isna' - The Research Scientist Pod
August 17, 2022 - This error occurs if you try to call isna() on a numpy.float64 object. If you want to evaluate whether a value is NaN or not in a Series or DataFrame object, you use can use the Series.isna() and DataFrame.isna() methods respectively.
🌐
Esri Community
community.esri.com › t5 › python-questions › attributeerror-float-object-has-no-attribute › td-p › 39532
Solved: AttributeError: 'float' object has no attribute 's... - Esri Community
December 12, 2021 - I'm hoping someone can tell me whats going on with the below bit of code. I keep getting the error AttributeError: 'float' object has no attribute 'setValue' and I'm not sure how to resolve it. Can someone please explain? NONFLOOD = "GRIDfield" NF1curs = arcpy.UpdateCursor(BuildingGridSe...
🌐
CopyProgramming
copyprogramming.com › howto › pandas-attributeerror-float-object-has-no-attribute-isnull
Python: Error in Pandas: 'float' object does not have attribute 'isnull'
June 17, 2023 - for no_confi in range(len(df)): if df['Confidence_Index_Status'][no_confi] == 0: df.iloc[no_confi,2:4] = np.nan df.iloc[no_confi,5:] = np.nan ... Python - Getting "AttributeError: 'float' object has, In my opinion problem is missing value in column, so use pandas methods Series.str.replace or Series.replace instead list …
🌐
PyTorch Forums
discuss.pytorch.org › autograd
AttributeError: 'float' object has no attribute 'dtype' when using extra arguments in jacrev() - autograd - PyTorch Forums
March 31, 2023 - Hi, I’m getting an error due to passing an argument (I think its the float k*r_trans) when using extra arguments to the function jacrev(). I tried declaring this as a tensor and then converting it back to a float inside the function pressureSpatialCompRealFunc but then it says the new variable ...
🌐
Reddit
reddit.com › r/learnpython › attributeerror: 'str' object has no attribute 'isna'
r/learnpython on Reddit: AttributeError: 'str' object has no attribute 'isna'
June 6, 2022 -

Hi,

Error is as follows:

AttributeError: 'str' object has no attribute 'isna' from the following code:

def sup_rank(row):
    if row['A'].isna():
        if row['B'].notna():
            return "Paid"
        else:
            return "Not Paid"
🌐
Unmet Hours
unmethours.com › question › 68535 › error-float-object-has-no-attribute-apply
Error: 'float' object has no attribute 'apply' - Unmet Hours
In the lines just above this, you've initialized these variables and set them to the temperature sensor values -- which are floats (numbers).
🌐
GitHub
github.com › pandas-dev › pandas › issues › 5062
df.apply(...): better error messages in case of NaN · Issue #5062 · pandas-dev/pandas
September 30, 2013 - cit = citations[1655:1660][["names"]] print cit names 1655 A;B 1656 NaN 1657 C;D 1658 E;F 1659 G;H s = cit.apply(lambda x: pandas.Series(x.split(';'))).stack() [...] C:\portabel\Python27\lib\site-packages\pandas\core\series.pyc in apply(self, func, convert_dtype, args, **kwds) 1952 values = lib.map_infer(values, lib.Timestamp) 1953 -> 1954 mapped = lib.map_infer(values, f, convert=convert_dtype) 1955 if len(mapped) and isinstance(mapped[0], Series): 1956 from pandas.core.frame import DataFrame C:\portabel\Python27\lib\site-packages\pandas\lib.pyd in pandas.lib.map_infer (pandas\lib.c:43742)() <timed exec> in <lambda>(x) AttributeError: 'float' object has no attribute 'split'
Author   jankatins