Python dataframe.pivot()

来源:互联网 发布:vb.net 多行注释 编辑:程序博客网 时间:2024/06/14 17:52

以下为python pandas 库的dataframe pivot()函数用法解析。

简而言之,我理解的pivot()的用途就是,将一个dataframe的记录数据整合成表格,而且是按照pivot(‘index=xx’,’columns=xx’,’values=xx’)来整合的。还有另外一种写法,
但是官方貌似并没有给出来,就是pivot(‘索引列’,‘列名’,‘值’)。

通过pivot()方法变换的dataframe

下面是官方描述:
官方描述

============================================================================

Reshape data (produce a “pivot” table) based on column values. Uses unique values from index / columns to form axes of the resulting DataFrame.
译:重塑数据(产生一个“pivot”表格)以列值为标准。使用来自索引/列的唯一的值(去除重复值)为轴形成dataframe结果。

For finer-tuned control, see hierarchical indexing documentation along with the related stack/unstack methods
译:为了精细调节控制,可以看和stack/unstack方法有关的分层索引文件.
、============================================================================
在数据分析的时候要记得将pivot结果reset_index()。

============================================================================

原创粉丝点击