我有 Pandas 系列 s,其中的一部分可以在下面看到。我基本上想将 s 的那些不为 0 的值的索引插入到列表 l 中,但不知道如何执行此操作。
2003-05-13 1
2003-11-2 0
2004-05-1 3
请您参考如下方法:
在 [7] 中是您要查找的内容:
In [5]: s = pd.Series(np.random.choice([0,1,2], 10))
In [6]: print s
0 0
1 1
2 0
3 1
4 0
5 2
6 1
7 1
8 2
9 2
dtype: int64
In [7]: print list(s.index[s != 0])
[1, 3, 5, 6, 7, 8, 9]
