开发者

How to merge or group dataframe?

I have a dataframe likes

   City    Age   column1  column2
0  Texas   20     7        5
1  Texas   35     8        1
2  Texas   30     8        2

I want to merge the column City with same city into 1 row and centralized, other columns are unchanged. So the output like

   City    Age   column1  column2
0          20     7        5
1  Texas   35     8        1
2          30     8        2
开发者_运维百科

Is it posible to do it with dataframe on pandas. The final target is that I want to save the dataframe to csv file likes

How to merge or group dataframe?


use pd.merge(df1,df2, how="choose one from inner,left,right, full joins", onleft = "df1 column name " ,onright = "df2 column name " )

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜