cancel
Showing results forย 
Search instead forย 
Did you mean:ย 
Data Engineering
Join discussions on data engineering best practices, architectures, and optimization strategies within the Databricks Community. Exchange insights and solutions with fellow data engineers.
cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

#N/A value is coming as null/NaN while using pandas.read_excel

Soumik
New Contributor II

Hi All,

I am trying to read an input_file.xlsx file using pandas.read_excel. I am using the below option 

import pandas as pd

df = pd.read_excel(input_file, sheetname = sheetname, dtype = str, na_filter= False, keep_default_na = False

Not sure but the value #N/A is coming as null/NaN, whereas the values N/A, NA etc which are default na values are coming as string, which is expected. Do anyone knows a solution or workaround ?

2 REPLIES 2

Brahmareddy
Esteemed Contributor

Hi Soumik,

How are you doing today? As per my understanding, It looks like Pandas is still treating #N/A as a missing value because Excel considers it a special type of NA. Even though you've set na_filter=False and keep_default_na=False, Pandas might still be handling it differently. A good workaround is to explicitly set na_values=[] in read_excel, which tells Pandas not to treat anything as NaN. Try updating your code like this: df = pd.read_excel(input_file, sheet_name=sheetname, dtype=str, na_values=[], keep_default_na=False). This should keep #N/A as a string instead of converting it to null. Let me know if it helps!

Regards,

Brahma

Soumik
New Contributor II

Hi Brahmareddy,

Thanks for your reply. I did try that option too, but the result is the same. It is still treating that as NaN and ultimately erroring out.

Thanks

Soumik

Join Us as a Local Community Builder!

Passionate about hosting events and connecting people? Help us grow a vibrant local communityโ€”sign up today to get started!

Sign Up Now