gpt4 book ai didi

Python pandas.read_excel 将 empy 单元格存储为 'None' 而不是 Nan 值

转载 作者:行者123 更新时间:2023-12-04 20:25:45 25 4
gpt4 key购买 nike

目前我正在使用 Pandas 和 Excel。我有很多 empy 单元格要处理的 excel 表。 Pandas 在解析时将它们识别为 Nan 值。我知道如何通过将其传递给 pandas excel 阅读方法来摆脱它们。

pandas.read_excel(keep_default_na=False)

或者
pandas.read_excel(na_filter=False)

但我想将 empy 单元格存储为 'None' 字符串。读取Excel文件时有什么办法吗?
问候,
埃德。

最佳答案

加载数据并将其保存到名为“df”的数据框中。
下一步是使用 df.fillna('value of your choice')

df = pandas.read_excel(keep_default_na=False)
df = df.fillna('None')

如果您现在打印 df,它将根据您的要求显示。

例子 :
df = pd.DataFrame([[1, 3], [3, 2, 4], [5]])
df = df.fillna('None')
print(df)

0 1 2
0 1 3 None
1 3 2 4
2 5 None None

希望这可以帮助。
如果您认为这不是您想要的,请发表评论。

关于Python pandas.read_excel 将 empy 单元格存储为 'None' 而不是 Nan 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60871254/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com