I have a .csv file which has both nan and blanks in it, I need to replace both of them separately, say 'nan' with 'None' and blanks with 'NA', how do I achieve it.
Maybe I wasn't clear earlier, I need to replace both the nan and the blank with 2 different values. nan is a separate string value in my file. Using .replace is not helping, because it's treating all blanks as nan and replacing them with 'None' and vice versa, so in the end I've all values either None or NA, but I NEED DIFFERENT ENTRIES FOR NAN AND BLANKS. This isn't a duplicate question Performing what's suggested on Replacing few values in a pandas dataframe column with another value, didn't help:
Col1 Col2
neb abc
ijd nan
987
2938
nan 909
Expected Result :
Col1 Col2
neb abc
ijd None
NA 987
2938 NA
None 909
I'm using :
df['Col1'] = df['Col1'].replace('nan','None')
df['Col1'] = df['Col1'].replace(np.nan,'NA')
df['Col2'] = df['Col2'].replace('nan','None')
df['Col2'] = df['Col2'].replace(np.nan,'NA')