比如資料為:
A
0 -1
1 -2
2 -3
3 1
4 2
5 3
6 4
7 5
8 -1
9 -1
10 -2
11 1
12 2
13 3
14 4
15 4
pandas如何通過索引,得出當前索引A值小于0,而下一個索引大于0的索引呢,比如上面索引2,10符合我的要求
uj5u.com熱心網友回復:
import pandas as pd
df = pd.DataFrame({'A':[-1,-2,-3,1,2,3,4,5,-1,-1,-2,1,2,3,4,4]})
dc1 = df['A']<0
dc2 = df['A'].shift(periods=-1,fill_value=https://bbs.csdn.net/topics/0)>0
print(df[dc1 & dc2])
好像沒有現成的函式,我的大致思路
uj5u.com熱心網友回復:
標題:pandas如何篩選出當前大于0,下一個資料小于0的索引呢?內容:pandas如何通過索引,得出當前索引A值小于0,而下一個索引大于0的索引呢?
標題和內容自相矛盾?
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/81731.html
上一篇:Python語音讀取的問題
下一篇:關于Python的文章替換
