开发者

How to merge or group dataframe?

开发者 https://www.devze.com 2022-12-07 22:45 出处:网络
I have a dataframe likes CityAgecolumn1column2 0Texas2075 1Texas3581 2Texas3082 I want to merge the column City with same city into 1 row and centralized, other columns are unchanged. So the output l

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

精彩评论

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

关注公众号