Home > OS >  New to Pandas - Indexing
New to Pandas - Indexing

Time:01-31

I have loaded a .CSV value into pandas dataframe (with pd.read_csv) in Jupyter and trying to replace a NaN value with boolean value 'False'.I was able to identify the row where given nan value is by:

dataframe[dataframe['columnname'].isnull()]

However now i am getting trobules choosing the field in order to replace it with desired 'False' value. I recall that in numpy it was sufficient to name row and column number (exemplary dataframe[3,5] to extract desired location.

In current case, whenever I try to use row number i got an error 'invalid key' Here are some methods that have failed:

dataframe[dataframe['columnname'].isnull()].fillna('False') - fills in every NAN value in row with 'False', instead of filling in one cell
dataframe[rownumber, columnnumber] - invalid key error
dataframe[rownumber, 'ColumnName'] - throws invalid key as well

I am really sorry to bother you with such silly question, I would really appreciate any hint.

CodePudding user response:

You have to read Index and selecting data:

dataframe[dataframe['columnname'].isnull()].fillna('False') - fills in every NAN value in row with 'False', instead of filling in one cell

df['columnname'] = df['columnname'].fillna(False)

Note: in one cell, do you mean in one column?

dataframe[rownumber, columnnumber] - invalid key error

df.iloc[rownumber, columnnumber]

dataframe[rownumber, 'ColumnName'] - throws invalid key as well

df.iloc[rownumber, df.columns.get_loc('ColumnName')]
  •  Tags:  
  • Related