2015-08-31 181 views
0

,我有以下的數據幀:在大熊貓數據幀行選擇後Reserializing行索引

import pandas as pd 
df = pd.DataFrame({ 'gene':["foo","bar","qux","woz"], 'cell1':[5,0,1,0], 'cell2':[12,90,13,0]}) 
df = df[["gene","cell1","cell2"]] 

,看起來像這樣:

gene cell1 cell2 
0 foo  5  12 
1 bar  0  90 
2 qux  1  13 
3 woz  0  0 

執行行選擇之後,我得到這樣的:

In [168]: ndf = df[(df[['cell1','cell2']] == 0).any(axis=1)] 

In [169]: ndf 
Out[169]: 
    gene cell1 cell2 
1 bar  0  90 
3 woz  0  0 

請注意,現在ndf有行索引13我如何將它重新索引到01

的expcted輸出是:

gene cell1 cell2 
0 bar  0  90 
1 woz  0  0 

我試過,但失敗:

ndf.reset_index 

怎樣做正確的方式?

回答

1

試試這個

ndf.reset_index(drop = True)