Column 2 probably has a float type:
>>> df 0 1 2 3 0 aa NaN a 1 bb NaN b 2 cc NaN c >>> df.dtypes 0 object 1 object 2 float64 3 object dtype: object
Hence the problem. If you don't mind converting the entire frame to object , you can:
>>> df.astype(object).fillna("UNKNOWN") 0 1 2 3 0 aa UNKNOWN a 1 bb UNKNOWN b 2 cc UNKNOWN c
Depending on whether there is non-row data, you may be more selective about converting the column types of the column and / or specifying dtypes when reading, but the above should work anyway.
Update: if you have dtype information that you want to save, instead of switching it back, I would go the other way and fill only those columns that you wanted, or using a loop with fillna :
>>> df 0 1 2 3 4 5 0 0 aa NaN a NaN 1 1 bb NaN b NaN 2 2 cc NaN c NaN >>> df.dtypes 0 int64 1 object 2 object 3 float64 4 object 5 float64 dtype: object >>> for col in df.columns[pd.isnull(df).all()]: ... df[col] = df[col].astype(object).fillna("UNKNOWN") ... >>> df 0 1 2 3 4 5 0 0 aa UNKNOWN a UNKNOWN 1 1 bb UNKNOWN b UNKNOWN 2 2 cc UNKNOWN c UNKNOWN >>> df.dtypes 0 int64 1 object 2 object 3 object 4 object 5 object dtype: object
Or (if you use all ), you might not even use fillna :
>>> df 0 1 2 3 4 5 0 0 aa NaN a NaN 1 1 bb NaN b NaN 2 2 cc NaN c NaN >>> df.ix[:,pd.isnull(df).all()] = "UNKNOWN" >>> df 0 1 2 3 4 5 0 0 aa UNKNOWN a UNKNOWN 1 1 bb UNKNOWN b UNKNOWN 2 2 cc UNKNOWN c UNKNOWN
DSM
source share