这应该很简单,但我是使用 python 工作的新手。有什么建议吗?
#original dataframe
df = pd.DataFrame({'year':[1,1,1,1,1],
'month':[4,4,4,4,4],
'mode': ['a','b','a','a','b']},
columns=['year','month','mode'])
#pivot/groupby etc
# df2=df.pivot(columns=('year','month'), values=('mode')).count()
#create this dataframe
df2 = pd.DataFrame({'year':[1],
'month':[4],
'a': [3],
'b':[2]},
columns=['year','month','a','b'])
我在 Koalas Apache Spark 环境中工作(文档),所以解决方案应该可以解决这个问题。
回首忆惘然
杨魅力
相关分类