I am trying to create a new column to a dataframe called names where the values = Y if the row value under 'name' = '-1A'. My dataframe is dynamic though so sometimes depending on what period i pull the data for this dataframe, my dataframe will be EMPTY (all rows under columns are nAn). When i try to add a column to this EMPTY dataframe though I am getting an AttributeError: ('float' object has no attribute 'isnull'", 'occurred at index 0')
I have a dataframe currently where the values look like this:
id | name |
---|---|
nAn | nAn |
nAn | nAn |
nAn | nAn |
I am trying to update my dataframe to look like this: | id | name | new_column| | -------- | -------- | -------- | | nAn | nAn | N | | nAn | nAn | N | | nAn | nAn | N |
When i try to account for a null row i get the attribute error: ('float' object has no attribute 'isnull'", 'occurred at index 0')
def names(row):
if row['name'].isnull():
return 'N'
elif row['name'].endswith(('-1A')):
return 'Y'
else:
return 'N'
I think this is related to the fact that my entire dataframe is empty currently but I still need to add a new column into it that will at least say N whenever there are null values. I'm not 100% sure what the error is telling me either