gpt4 book ai didi

python - 从列表中删除 nan - Python

转载 作者:太空狗 更新时间:2023-10-30 01:50:13 25 4
gpt4 key购买 nike

我试图从列表中删除“nan”,但它拒绝删除。 np.nan 和 'nan' 我都试过了。

这是我的代码:

ztt = []
for i in z:
if i != 'nan':
ztt.append(i)
ztt

或:

ztt = []
for i in z:
if i != np.nan:
ztt.append(i)
ztt

我仍然得到输出:

[[46.0, 34.0, 32.0, 40.0, 34.0, 29.0, 38.0, 39.0, 45.0, 32.0, 28.0, 43.0],
[32.0, 30.0, 67.0, 66.0, 28.0, 19.0, 39.0, 32.0, 51.0, 28.0, 20.0, 36.0],
[29.0, 24.0, 37.0, 31.0, 32.0, 34.0, 28.0, 31.0, 28.0, 33.0, 28.0, 39.0],
[27.0, 29.0, 35.0, nan, nan, nan, nan, nan, nan, nan, nan, nan]]

谁知道出了什么问题?

最佳答案

for i in z:
if not math.isnan(i):
ztt.append(i)

关于python - 从列表中删除 nan - Python,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45375381/

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