2024-03-29 11:48:34 发布
网友
我有一组数据,发现两行需要合并到一个值上。我运行了以下命令:
pd.concat(g for _, g in cityData_df.groupby("city") if len(g) > 1)
并得到以下结果:
city driver_count type 84 Port James 15 Suburban 100 Port James 3 Suburban
如何在cityData_df中合并这两行,使Port James只有一个条目和18个驱动程序
这应该可以做到:
cityData_df.groupby(['city', 'type'])['driver_count'].sum().reset_index()
这应该可以做到:
相关问题 更多 >
编程相关推荐