Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Is NaN a float?
#1
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:

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.
Reply


Messages In This Thread
Is NaN a float? - by Pedroski55 - Jun-08-2024, 06:19 AM
RE: Is NaN a float? - by Gribouillis - Jun-08-2024, 07:21 AM
RE: Is NaN a float? - by Pedroski55 - Jun-08-2024, 08:58 AM
RE: Is NaN a float? - by Gribouillis - Jun-08-2024, 10:13 AM
RE: Is NaN a float? - by snippsat - Jun-08-2024, 11:25 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  python calculate float plus float is incorrect? sirocawa 6 686 Apr-16-2024, 01:45 PM
Last Post: DeaD_EyE
  Comaparing Float Values of Dictionary Against A Float Value & Pick Matching Key firebird 2 3,577 Jul-25-2019, 11:32 PM
Last Post: scidam

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020