python - pandas select FROM .... TO -
i have dataframe
c v s d loc 1 2 3 4 x 5 6 7 8 1 2 3 4 5 6 7 8 y 9 10 11 12
how can select rows loc x y , inport them in csv
use idxmax
first values of index true
in condition:
df = df.loc[(df['loc'] == 'x').idxmax():(df['loc'] == 'y').idxmax()] print (df) c v s d loc 0 1 2 3 4 x 1 5 6 7 8 nan 2 1 2 3 4 nan 3 5 6 7 8 y
Comments
Post a Comment