pandas - 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
解决方案
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")]
推荐阅读
- javascript - 尝试导入错误:“__exports”未导出
- dataframe - 将 Julia 数据框列标题更改为小写?
- jquery - 在 DataTable 中动态呈现列 - Column.Render 属性
- python - 为什么下载功能从部署在heroku上的应用程序不起作用
- mysql - 您如何确保在更新新库存时,仍然使用触发器记录旧库存?
- php - 如果需要,正则表达式如何转义双引号
- sonarqube - 无法通过 API 获取严重性信息
- c# - 连接到 Kafka 的 docker 实例时出现 C# 错误
- html - 使 ap:dialog 中的 p:editor 适合对话框大小
- r - 在R中将字符串分解为多个虚拟变量