python - 如何在数据框中打印您要查找的值的行和列
问题描述
所以我做了这个数据框
alp = "abcdefghijklmnopqrstuvwxyz0123456789"
s = "carl"
for i in s:
alp = alp.replace(i,"")
jaa = s+alp
x = list(jaa)
array = np.array(x)
re = np.reshape(array,(6,6))
dt = pd.DataFrame(re)
dt.columns = [1,2,3,4,5,6]
dt.index = [1,2,3,4,5,6]
dt
1 2 3 4 5 6
1 c a r l b d
2 e f g h i j
3 k m n o p q
4 s t u v w x
5 y z 0 1 2 3
6 4 5 6 7 8 9
我想搜索一个值,并打印它的行(索引)和列。例如'h',我想要的输出是2,4。有没有办法得到那个输出?
解决方案
row, col = np.where(dt == "h")
print(dt.index[row[0]], dt.columns[col[0]])
推荐阅读
- outlook - 如何在不存储在 webmail 收件箱中的情况下直接获取电子邮件?
- java - Java Web 服务请求参数返回为 null
- angular - 加载ctrl微调器启动时禁用硬件后退按钮?
- javascript - 如何在我的 vue 模板脚本中有条件地调用 apollo 客户端?
- shell - 将 CSV 转换为列分隔值,但将值放在最右边
- asp.net-mvc - ASP.Net MVC 日期验证总是说“字段必须是数字”(???)
- reactjs - 如何渲染/动画出离开数组的项目
- elasticsearch - ElasticSearch 查询返回脚本分数错误 - 意外字符“[”
- python - urlopen 错误 [Errno 11001] 本地驱动器的 getaddrinfo 失败
- postgis - ST_Union() 处理时间过长