2016-12-06 40 views
1

,因爲我有數據幀遵循如何在時間找到數據幀的數據,在條件列表

In [107]: xx 
Out[107]: 
    1   2   3   4 
0 0 -1.234881 0.039231 -0.399870 
1 1 -1.761733 -1.186537 0.043678 
2 2 0.707564 -0.270639 -0.251519 
3 3 -0.979584 0.476025 -1.587889 
4 4 -0.576429 1.987681 -0.322581 
5 5 -0.695509 1.285029 0.393906 
6 6 -0.036627 -0.380702 -0.170813 
7 7 0.673423 0.860289 -0.774651 
8 8 -1.000333 0.978760 0.256645 
9 9 -0.446005 -0.584627 0.187244 

,條件是一樣

con = [2,4,6,8] 
column = 1

有沒有我可以使用的功能,我可以得到如下結果:

1   2   3   4 
2 2 0.707564 -0.270639 -0.251519 
4 4 -0.576429 1.987681 -0.322581 
6 6 -0.036627 -0.380702 -0.170813 
8 8 -1.000333 0.978760 0.256645 

謝謝!

+0

你看看下面的帖子嗎? http://stackoverflow.com/questions/14661701/how-to-drop-a-list-of-rows-from-pandas-dataframe http://stackoverflow.com/questions/37502298/python-pandas-get-index -from-column-value –

+0

似乎像第一列與索引一樣...是嗎? – MMF

回答

4

可以使用.isin()方法:

con = [2,4,6,8] 
xxx[xxx["1"].isin(con)] 

enter image description here

3

使用isin

In [29]: df[df['1'].isin(con)] 
Out[29]: 
    1   2   3   4 
2 2 0.707564 -0.270639 -0.251519 
4 4 -0.576429 1.987681 -0.322581 
6 6 -0.036627 -0.380702 -0.170813 
8 8 -1.000333 0.978760 0.256645