2015-08-31 182 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)