pandas 系列中的缺失值检查 [英] Missing value check in pandas series
本文介绍了 pandas 系列中的缺失值检查的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用Pandas包生成了一个流量序列:
data = np.array(data)
index = date_range(time_start[0],time_end[0],freq='30S')
s = Series(data, index=index)
示例的输出如下所示:
2013-07-02 10:04:30 13242.0
2013-07-02 10:05:00 12354.3
................... .......
这里第一列是索引,第二列是值。我的任务是收集它们的值(第二列)丢失的所有时刻。
我的想法是这样的:
for i in s:
if isnull(i):
s.iloc['i']
但"None"不能用于引用索引...
如果缺失值和s都很大,这是否会提高效率?有没有更好的主意?
推荐答案
In [1]: import pandas as pd
In [2]: s = pd.Series([1, 2, 3, np.NaN, np.NaN, 5, 6])
In [3]: s.isnull()
Out[3]:
0 False
1 False
2 False
3 True
4 True
5 False
6 False
dtype: bool
In [4]: s[s.isnull()]
Out[4]:
3 NaN
4 NaN
dtype: float64
In [5]: s.index[s.isnull()]
Out[5]: Int64Index([3, 4], dtype=int64)
这篇关于 pandas 系列中的缺失值检查的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文