python - Reserializing row index after row selection in pandas data frame -
i have following data frame:
import pandas pd df = pd.dataframe({ 'gene':["foo","bar","qux","woz"], 'cell1':[5,0,1,0], 'cell2':[12,90,13,0]}) df = df[["gene","cell1","cell2"]]
that looks this:
gene cell1 cell2 0 foo 5 12 1 bar 0 90 2 qux 1 13 3 woz 0 0
after performing row selection this:
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
note ndf
has row index 1
, 3
how can re index 0
, 1
.
the expcted output is:
gene cell1 cell2 0 bar 0 90 1 woz 0 0
i tried failed:
ndf.reset_index
what's right way it?
try 1
ndf.reset_index(drop = true)
Comments
Post a Comment