我有看起來像這樣的數(shù)據(jù):example = pd.Series([0,0,0,2,2,0], index = [2000, 2001, 2002, 2003, 2004, 2005])如何找到與條件第一次為真對應(yīng)的索引?例如,我想找到與第一個(gè)非零條目對應(yīng)的索引,在示例數(shù)據(jù)中為 2003。
3 回答

三國紛爭
TA貢獻(xiàn)1804條經(jīng)驗(yàn) 獲得超7個(gè)贊
通過使用 nonzero
example.index[example.nonzero()[0][0]]
Out[267]: 2003
添加回答
舉報(bào)
0/150
提交
取消