Kiran Gopi
Kiran Gopi

Reputation: 35

'NA' handling in python pandas

i have a dataframe with name,age fieldname,name column has missing value and NA when i read the value using pd.read_excel,missing value and NA become NaN,how can i avoid this issue. this is my code

import pandas as pd
data = {'Name':['Tom', '', 'NA','', 'Ricky',"NA",''],'Age':[28,34,29,42,35,33,40]}
df = pd.DataFrame(data)
df.to_excel("test1.xlsx",sheet_name="test")
import pandas as pd
data=pd.read_excel("./test1.xlsx")

getting thisexpected one

Upvotes: 1

Views: 140

Answers (1)

Toukenize
Toukenize

Reputation: 1420

To avoid this, just set the keep_default_na to False:

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

Upvotes: 2

Related Questions