I have the following problem: I am reading a csv file with missing values by using
pd.read_csv(f_name, sep=sep, header=hdr, parse_dates=True, index_col=date_col, quotechar=quote)
The dataframe I get has 'nan's in it (I was expecting 'NaN's with the Upper cases). Now if I try to replace those nan's with zerosby using
df.fillna(0)
my df doesn't change (I still see nan's in it) My guess is that fillna is not working because I have nan (lowercase) instead of NaN (uppercase). Am I correct? If yes, do you have an idea why pd.read.csv returns a dataframe with lowercase nan's? I am using Python 2.7.6 (Anaconda bundle)
Many thanks for your help.
df.fillna(0)
returns a new dataframe; it does not alter df
.
So instead use:
df = df.fillna(0) # assigns df to a new dataframe
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With