-1

I've imported data from a csv file which has columns NAME, ADDRESS, PHONE_NUMBER. Sometimes, at least 1 of the columns has a missing value for that row. e.g

0 - Bill, Flat 2, 555123
1 - Katie, NaN, NaN
2 - Ruth, Flat 1, ?

I'm trying to get the NaN values to fill a new table which I can do if a filler value has been put in such as: newDetails = details [details['PHONE_NUMBER']=="?"] which gives me:

2 - Ruth, Flat 1, ?

I tried to use fillna but I couldn't find the syntax that would work.

EdChum
  • 376,765
  • 198
  • 813
  • 562
M.Throw
  • 145
  • 1
  • 2
  • 11
  • 2
    Can you post what the desired output should be as you've not explained what the missing values should be filled with, also are you asking how to replace `?` with `NaN`? – EdChum Nov 30 '16 at 14:23

1 Answers1

2

Pandas fillna (pandas.DataFrame.fillna) is quite simple. Suppose your data frame is df. Here's how you can do.

df.fillna('_missing_value_', inplace=True)

It looks like you have different fields with missing value. May be try this:

df = df.where((pd.notnull(df)),'_missing_value_')

Edit1 to replace in a column

If you want to replace a column Flat 2, here's how:

col_flat = df[['Flat 2']].fillna('?')
df['Flat 2'] = col_flat['Flat 2']
Krishna Sunuwar
  • 2,915
  • 16
  • 24
  • Thanks for the reply. This kinda worked but it replaced all of the NaN values in every column rather than ones in a specific column. Also, for some reason, I have longer numbers such as 140191 which are now being shown as 1.40191e+06 – M.Throw Nov 30 '16 at 14:42