Jun-08-2024, 06:19 AM
Is NaN a float?
The girlfriend works for a company that exports agrochemicals. She sent me an Excel with about 250 customers details, mostly in Africa and South America. I will try and extract customer number, company name, contact person and email, then batch send emails to all the customers, with the latest info.
I open the Excel:
I tried to identify NaN values, so I could skip customers whose email is not recorded in the Excel. In the dictionary, NaN is nan:
I can str(d['邮箱']) and get "nan" so I used that to eliminate customers without email records.
The girlfriend works for a company that exports agrochemicals. She sent me an Excel with about 250 customers details, mostly in Africa and South America. I will try and extract customer number, company name, contact person and email, then batch send emails to all the customers, with the latest info.
I open the Excel:
df = pd.read_excel(path2XL) print(df.loc[2, : ])The above gives, for example:
Output:客户编码 11820122.0
客户名称 WILLOWOOD FZE (Free Zone Establishment)
国家 美国
网址 NaN
联系人 NaN
邮箱 NaN
电话 NaN
公司地址 NaN
主要产品 NaN
Name: 2, dtype: object
to make things easier, I used .to_dict() on each row, extracted the bits I want and saved to json. I tried to identify NaN values, so I could skip customers whose email is not recorded in the Excel. In the dictionary, NaN is nan:
d = df.iloc[2, :].to_dict() d['邮箱'] # '邮箱' = 'email'
Output:nan
and type(d['邮箱'])gives:
Output:<class 'float'>
Is NaN a float? Seems weird!I can str(d['邮箱']) and get "nan" so I used that to eliminate customers without email records.