2

I got an issue, hopefully someone has a great solution.

I am reading an Excel file. And I use keep_default_na=False because there is a productname called "NA" and I dont want pandas changing it to NaN.

df = pd.read_excel('Import_orders.xlsx', keep_default_na=False)

But the problem is when i run below code, it does nothing. Because there are no NaN values to fill. Because i used "keep_default_na=False". Is there a way to fill the empty fields. Thanks in advance!

df['Action for Contact'] = df['Action for Contact'].fillna('Update') 
hii
  • 77
  • 6

1 Answers1

1

You can specify the values considered as nan, just exclude NA, like so:

na_values = ['',
             '#N/A',
             '#N/A N/A',
             '#NA',
             '-1.#IND',
             '-1.#QNAN',
             '-NaN',
             '-nan',
             '1.#IND',
             '1.#QNAN',
             '<NA>',
             'N/A',
             'NA',
             'NULL',
             'NaN',
             'n/a',
             'nan',
             'null']

na_values.remove('NA')

pd.read_excel(file_path, keep_default_na=False, na_values=na_values)
Andreas
  • 8,694
  • 3
  • 14
  • 38