在pandas系列中缺少值检查

Jin*_*Jin 2 python series pandas

我使用pandas包生成了这样的交通流量系列:

data = np.array(data)
index = date_range(time_start[0],time_end[0],freq='30S')
s = Series(data, index=index)
Run Code Online (Sandbox Code Playgroud)

样本输出如下:

2013-07-02 10:04:30     13242.0
2013-07-02 10:05:00     12354.3    
...................     .......
Run Code Online (Sandbox Code Playgroud)

这里第一列是索引,第二列是值.我的任务是收集他们的价值观(第二栏)缺失的所有时刻.

我的想法是这样的:

for i in s:
   if isnull(i):
      s.iloc['i'] 
Run Code Online (Sandbox Code Playgroud)

但'无'不能用来引用索引......

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

roo*_*oot 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)
Run Code Online (Sandbox Code Playgroud)