I have dates in this format 12/29/2011 as a string I guess and I only need Year so I write this function to extract year only but I got
"ValueError: cannot convert float NaN to integer"
Seems like I have Nan's somewhere and only solution I can think of is to drop the rows with Nan's but I cant do that coz I need the data from other columns.
def get_year(date):
year = ''
try:
year = date[-4:]
except TypeError:
year = str(date)[0:4]
return (year).astype(int)
The get_year function works when I use this code
for i in df.index:
if (not pd.isna(df['yearOpened'][i]) and get_year(df['yearOpened'][i]) > 1955):
print('something')
I am using .loc and wants to know how to skip Nan's using .loc
`df.loc[get_year(df['yearOpened'])]`