gpt4 book ai didi

python Pandas : selecting rows whose column value is null/None/nan

转载 作者:太空狗 更新时间:2023-10-29 17:24:44 26 4
gpt4 key购买 nike

<分区>

如何选择列中值为 none 的 DataFrame 的那些行?

我已将这些编码为 np.nan,但无法与此类型匹配。

In [1]: import numpy as np

In [2]: import pandas as pd

In [3]: df = pd.DataFrame([[1, 2, 3], [3, 4, None]])

In [4]: df
Out[4]:
0 1 2
0 1 2 3.0
1 3 4 NaN

In [5]: df = df.fillna(np.nan)

In [6]: df
Out[6]:
0 1 2
0 1 2 3.0
1 3 4 NaN

In [7]: df.iloc[1][2]
Out[7]: nan

In [8]: df.iloc[1][2] == np.nan
Out[8]: False

In [9]: df[df[2] == None]
Out[9]:
Empty DataFrame
Columns: [0, 1, 2]
Index: []

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