最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

在Pandas数据框中旋转数据表

SEO心得admin41浏览0评论
本文介绍了在Pandas数据框中旋转数据表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个要求,我要在其中计算值并将它们放在数据透视表中.

I have a requirement where in I am trying to count the values and Put them in the pivot table.

这是我的数据框,

Cola Colb Apple Rippened Orange Rippened Apple UnRippened Mango UnRippened

我希望输出是这样的,

Rippened UnRippened Apple 1 1 Mango 0 1 Orange 1 0

请分享您的想法.

推荐答案

IIUC:

In [178]: d.pivot_table(index='Cola', columns='Colb', aggfunc='size', fill_value=0) Out[178]: Colb Rippened UnRippened Cola Apple 1 1 Mango 0 1 Orange 1 0
发布评论

评论列表(0)

  1. 暂无评论