0

I have 2 columns A(ID) and B, relation is such that for every unique value in column A, there is a fixed value for column 2. But few values in column 2 are 'nan' values, hence I have to substitute them with corresponding values of them from column A. How to do this?

enter image description here So this 'nan' in B is to be replaced with 2, as it has y in col A and for y in col A value for column B is 2. I need to do this for a larger dataset.

Prashant
  • 1
  • 1

1 Answers1

0

try fillna() and specify column and value you want to replace NaN in as dict

df = df.fillna({'B': 2})

Or see docs

alikhtag
  • 316
  • 1
  • 6