gpt4 book ai didi

python - 填充列表 nan 值

转载 作者:太空宇宙 更新时间:2023-11-03 14:05:07 25 4
gpt4 key购买 nike

如何在列表中用 0 填充 nan 值。我可以为数据框做,但不知道如何为列表做?

listname=listname.fillna(0)

这不起作用。

最佳答案

您可以转换为 pandas 系列并返回列表

pd.Series(listname).fillna(0).tolist()

考虑列表listname

listname = [1, np.nan, 2, None, 3]

然后

pd.Series(listname, dtype=object).fillna(0).tolist()

[1, 0, 2, 0, 3]

关于python - 填充列表 nan 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44403116/

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