【发布时间】:2016-10-16 15:13:48
【问题描述】:
我有一个数据框,在清理和合并之后,它最终处于我有多行具有相同索引值的状态。
我需要合并这些重复的行并得到一个数据框,其中每次重复运行都有一行。
感觉这应该是处理数据帧时的标准操作,但我似乎无法弄清楚如何让 Pandas 做到这一点。
我找到的最佳答案在这里:Merge two rows in the same Dataframe if their index is the same?
但是,那里提出的解决方案以“groupby”对象而不是数据框结束。由于我想在框架上进行进一步的 groupby,所以我不知道如何进行。
pandas 方法中是否有一个标准函数用于压缩多行共享相同索引的数据帧,并返回一个新的数据帧?
例如:
visits revenue product-type
product1 200 50 stockings
product1 50 100 #n/a
product2 150 20 toy
... .. .. ..
到
visits revenue product-type
product1 250 150 stockings
product2 150 20 toy
... .. .. ..
【问题讨论】:
标签: python-3.x pandas merge ipython