-1

I have some NAs and would like to fill them with values in another column in the same row.

df = pd.DataFrame({"column A": ["Atlanta", "Atlanta", "New York", "",""], 
                   "column B": ["AT", "AT", "NY", "1", ""]})
columnA ColumnB
Atlanta AT
Atlanta AT
Newyork NY
1

Expected output:

columnA ColumnB
Atlanta AT
Atlanta AT
Newyork NY
1 1
Tomerikoo
  • 18,379
  • 16
  • 47
  • 61
Daven1
  • 135
  • 8

1 Answers1

0

You can Simply Use the fillna with the Column Name like this:

df['column A'].fillna(df['column B'])
Tomerikoo
  • 18,379
  • 16
  • 47
  • 61
Hamza
  • 26