python - Python:使用 col1('x_y')中的字符串作为坐标创建热图?
问题描述
我想使用位置(x_y)作为坐标,值作为颜色强度来创建一个热图。
这是数据框:
Position Value
1_5 1
1_6 -1
1_7 0.5
2_5 6
2_6 -3
2_7 -5
中间步骤可能是像这样创建一个数据框(x,y 的顺序无关紧要):
1 2
5 1 6
6 -1 -3
7 0.5 -5
解决方案
我们这样split
做unstack
df.index=pd.MultiIndex.from_tuples(df.Position.str.split('_').apply(tuple))
s=df.Value.unstack(0)
s
1 2
5 1.0 6.0
6 -1.0 -3.0
7 0.5 -5.0
推荐阅读
- r - 当一些文件包含错误时并行处理运行多个文件
- python - 如何将自定义字段添加到 ModelView (flask-appbuild)
- reactjs - 如何使用 yup 和 formik 有条件地验证
- fork - FORK 不适用于 root 用户以外的用户
- selenium - 无法获取元素的文本。试过 getText() 和 getAttribute("innerHTML")
- mysql - Slick Transaction 已提交,但未保存在表 [Mysql] 中
- html - 为什么我的 css 不能仅在我的代码的某些部分上工作?
- vb.net - 设置了文本框离开事件,当文本框包含字母时,其他清除按钮无法删除
- android - adb.exe 的问题 - AdbHostServer.cpp:93:无法连接到端口上的 adb 守护程序:5037
- android - 防止 Samsung Device care 删除文件