从python中的记录创建列

Posted

技术标签:

【中文标题】从python中的记录创建列【英文标题】:create columns from records in python 【发布时间】:2021-08-24 09:02:01 【问题描述】:

我有一个 df 我想占据 2 列:

我想获得另一个 df,它将日期分组并给我类别总数。

我如何在 python 中做到这一点

【问题讨论】:

请提供可重现格式的样本,以便我们使用它。 【参考方案1】:

这应该可以工作

import pandas as pd
df.pivot_table(index='date', columns='category', aggfunc=len, fill_value=0)

【讨论】:

以上是关于从python中的记录创建列的主要内容,如果未能解决你的问题,请参考以下文章