将数据透视表转换为数据框 [英] Convert pivot tables to dataframe
本文介绍了将数据透视表转换为数据框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
例如,我有一个数据透视表,
I have a pivot table, for example,
first second
bar one
two
foo one
two
如何将其恢复为包含所有值以及行和列填充的普通数据框?
How do I change it back to a normal dataframe with all values and rows and column filled?
first second
bar one
bar two
foo one
bar two
推荐答案
如果表是数据透视表的名称,而 df 是新的数据框,
if table is the name of your pivottable and df is the new dataframe,
df = table.reset_index()
这篇关于将数据透视表转换为数据框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文