如何在pandas中的Excel枢轴表函数中使用分组功能?
我有熊猫数据框架。
id | Score | Action_flag |
---|---|---|
S11 | 0.585366 | Not Traded |
P555 | 0.457778 | Not Traded |
B28 | 0.636154 | Not Traded |
A859 | 0.000000 | Traded |
P556 | 0.761905 | Not Traded |
Y461 | 0.333333 | Not Traded |
S121 | 0.444444 | Not Traded |
K481 | 0.000000 | Traded |
S122 | 1.000000 | Not Traded |
R556 | 0.000000 | Traded |
R627 | 0.602778 | Traded |
In excel using pivot table and grouping我能够做到这一点。
如何使用pandas
I have a pandas dataframe.
id | Score | Action_flag |
---|---|---|
S11 | 0.585366 | Not Traded |
P555 | 0.457778 | Not Traded |
B28 | 0.636154 | Not Traded |
A859 | 0.000000 | Traded |
P556 | 0.761905 | Not Traded |
Y461 | 0.333333 | Not Traded |
S121 | 0.444444 | Not Traded |
K481 | 0.000000 | Traded |
S122 | 1.000000 | Not Traded |
R556 | 0.000000 | Traded |
R627 | 0.602778 | Traded |
In excel using pivot table and grouping I was able to do this.
How to achieve this using pandas
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
iiuc,您可以使用
pd.cut
创建垃圾箱,然后使用crosstab
获取每个操作标志的计数。最后,分配
对新列“ Grand_total”的行总计:输出:
IIUC, you could create bins using
pd.cut
, then usecrosstab
to get the counts each each action flag. Finally,assign
the row-wise totals to a new column "Grand_total":Output: