有人可以看到爲什麼這不起作用嗎?我試圖從我的Python List /數組中刪除nan值。從Python列表中刪除nan值
import math
import numpy as np
def clean_List_nan(List):
Myarray=np.array(List)
x = float('nan')
for elem in Myarray:
if math.isnan(x):
x = 0.0
return Myarray
oldlist =[nan, 19523.3211203121, 19738.4276377355, 19654.8478302742, 119.636737571360, 19712.4329437810, nan, 20052.3645613346, 19846.4815936009, 20041.8676619438, 19921.8126944154, nan, 20030.5073635719]
print(clean_List_nan(oldlist))