When Python pandas dataframe packet aggregation, incorporated GROUP NAME column method

 

Reprint, delete the invasion, thanks to the original author

When using packet aggregation do pandas, packet group name is changed to the default index, FIG.

= tdf.groupby Grouped ( 'uid')
Mean = grouped.mean ();
forwardmeandf pd.DataFrame = (Mean)
code tdf is when after a dataframe to uid grouped and averaged for each group into dataframe, group name incorporated into the index

This is very inconvenient for us to get through index value since uid too long. This question troubled me for a long time, finally saw the solution in the official document, as long as the time specified as_index = false packets can be.

 

grouped = tdf.groupby('uid',as_index=False)
mean=grouped.mean();
forwardmeandf=pd.DataFrame(mean)

This will not only help us do take advantage of index selection, and the table does not use uid and groups do join are also possible.

In addition. . . Information on domestic pandas too little, it is recommended to see the official documents.

----------------
Disclaimer: This article is the original article CSDN bloggers "liujia_rik", and follow CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement. .
Original link: https: //blog.csdn.net/u011199646/article/details/48109839

发布了89 篇原创文章 · 获赞 68 · 访问量 32万+

Guess you like

Origin blog.csdn.net/symoriaty/article/details/103102793