在pandas系列中缺少值检查

时间:2013-07-03 17:34:50

标签: python pandas series

我使用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'] 

但“无”不能用于引用索引...

如果缺失值和s都很大,这会导致效率吗?有更好的主意吗?

1 个答案:

答案 0 :(得分:5)

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)