2017-10-17 88 views
2
 A   B C D  E  
0 1.0 2013-01-02 1.0 1 test 
1 1.0 2014-01-02 1.0 2 car 
2 1.0 2015-01-02 1.0 3 tested 
3 1.0 2016-01-02 1.0 4 train 

如何根據列E中的值例如分割熊貓數據框以包含上面的連續三行,從'測試'到'測試'?如何在兩列值之間按行分割熊貓數據框?

+1

你認爲答案是...告訴我們什麼你的預期結果看起來像。 – piRSquared

回答

1

IIUC,使用pd.DataFrame.iloc

df.iloc[0:3] 

    A   B C D  E 
0 1.0 2013-01-02 1.0 1 test 
1 1.0 2014-01-02 1.0 2  car 
2 1.0 2015-01-02 1.0 3 tested 
1

我爲什麼我不上來這個解決方案,醜陋但工作..

df.iloc[df.index[(df.E=='test').eq(1)].values[0]:df.index[(df.E=='tested').eq(1)].values[0]+1,:] 

Out[151]: 
    A   B C D  E 
0 1.0 2013-01-02 1.0 1 test 
1 1.0 2014-01-02 1.0 2  car 
2 1.0 2015-01-02 1.0 3 tested 
相關問題