Python中文
首页
教程
问答
标签
搜索
登录
注册
组合crosstabpivotgroupby for Pandas datafram
回答此问题可获得
20
贡献值,回答如果被采纳可获得
50
分。
<p>我认为这是一个相当简单的问题,但我找不到另一个类似案件的答案。在</p> <p>我有一个Pandas数据帧,如下所示:</p> <pre><code> group1 group2 meandiff lower upper reject 0 bacc dry_sed 2575.1697 2033.6713 3116.6681 True 1 bacc junc_hal -81.8513 -555.8132 392.1106 False 2 bacc other_trees -1.2333 -512.6246 510.1579 False 3 bacc phrag 613.2256 0.4309 1226.0204 True 4 bacc water -1074.4667 -1687.2614 -461.6719 True 5 bacc wet_sed -437.1854 -943.2217 68.8508 False 6 dry_sed junc_hal -2657.0210 -3068.3186 -2245.7234 True 7 dry_sed other_trees -2576.4030 -3030.3269 -2122.4792 True 8 dry_sed phrag -1961.9441 -2527.6677 -1396.2204 True 9 dry_sed water -3649.6364 -4215.3600 -3083.9127 True 10 dry_sed wet_sed -3012.3551 -3460.2374 -2564.4728 True 11 junc_hal other_trees 80.6179 -290.1464 451.3823 False 12 junc_hal phrag 695.0769 193.6165 1196.5373 True 13 junc_hal water -992.6154 -1494.0758 -491.1550 True 14 junc_hal wet_sed -355.3341 -718.6767 8.0084 False 15 other_trees phrag 614.4590 77.4825 1151.4354 True 16 other_trees water -1073.2333 -1610.2098 -536.2569 True 17 other_trees wet_sed -435.9521 -846.9253 -24.9788 True 18 phrag water -1687.6923 -2321.9951 -1053.3895 True 19 phrag wet_sed -1050.4111 -1582.2901 -518.5320 True 20 water wet_sed 637.2812 105.4022 1169.1603 True </code></pre> <p>我想在group1和group2之间创建一个列联表,但是在每个单元格中放入Reject列中的值。在</p> <p>应该是这样的:</p> ^{pr2}$ <p>NA只是作为参考,可能有任何数字。在</p> <p>有没有一种直接的方法来总结这种数据?在跳转到使用循环分析表之前,我想确定没有简单直接的方法来实现这一点。在</p> <p>提前谢谢。在</p>
0 条评论
分类:
Python问答
请先
登录
后评论
默认排序
时间排序
1 个回答
匿名
1天前
擅长:python、mysql、java
<p>假设您的数据帧名为<code>df</code>,您可以执行以下操作:</p> <pre><code>df['reject_flag'] = df['reject'].astype(int) output = df.pivot_table(index='group1', columns='group2', values='reject_flag') </code></pre> <p>这给了你以下信息:</p> ^{pr2}$
请先
登录
后评论
针对此问题:
更多的回答
关注
89
关注
收藏
1
收藏,
216
浏览
网友 提问于 2天前
相关Python问题
如何在python中从数据帧列中删除分类值?
3 回答
如何在python中从数据帧列表中删除引号
4 回答
如何在python中从数据帧创建列表
5 回答
如何在Python中从数据帧创建嵌套的JSON
9 回答
如何在Python中从数据帧显示wordcloud
8 回答
如何在Python中从数据帧的时间戳中删除字符
9 回答
如何在Python中从数据帧绘制简单绘图?
3 回答
如何在python中从数据帧行提取具有特定长度的范围?
7 回答
如何在python中从数据帧设置dict中的值
7 回答
如何在Python中从数据库中获得一个结果
1 回答
如何在python中从数据框中绘制分类条形图
9 回答
如何在Python中从数据框中选择特定细节?
8 回答
如何在python中从数据集中删除unicode
3 回答
如何在python中从数据集中删除某些数值?
2 回答
如何在python中从数据集中选择行
10 回答
如何在Python中从数组中删除元素
1 回答
如何在python中从数组中删除单个倒逗号?
5 回答
如何在python中从数组中删除对象?
7 回答
如何在python中从数组中删除引号
5 回答
如何在python中从数组中删除所有最小值
1 回答