首页 > 解决方案 > How to find the row whcih contains from the pivot table

问题描述

My DF is below. FInd the rows contains

gender  FEMALE  MALE    OTHER
AGE         
[15-20]     0   1   0
[25-30]     0   1   0

df_1[df_1['AGE'].str.contains("15-20")]

Expected Out

gender  FEMALE  MALE    OTHER
    AGE         
    [15-20]     0   1   

标签: pandas

解决方案


You can use str.contains:

df.loc[df.index.str.contains("15-20")]

Or as suggested by @anky_91, the loc operation can be removed:

df[df.index.str.contains("15-20")]

推荐阅读