繁体   English   中英

如何在 pandas 中查找某些列变量的行

[英]How to find the row for some column variable in pandas

例如,在一个大数据库中,我知道列中项目的值,那么我将如何获得相应的索引和列

   col2 col3
id      
1   3   8
2   4   3
3   5   9

代码:

df[df.isin([3])].stack().index.tolist()

结果:(row_index,column_name)

[(1, 'col2'), (2, 'col3')]

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM