【发布时间】:2021-06-22 21:45:30
【问题描述】:
我有以下数据框:
unique_id person_id fruit_name poduct guest
92 11 apple silver Miller
93 12 cherry bronze Gus
967 121 orange purple Mike
94 176 apple silver Miller
95 176 banana gold John
96 176 orange purple Mike
445 111 apple silver Miller
100 112 cherry bronze Gus
232 111 apple silver Miller
355 555 cherry bronze Gus
我想抓取在 person_id 列下找到的任何重复值并将它们移动到与原始行相邻的位置,这是预期输出的示例:
unique_id person_id fruit_name poduct guest unique_id_1 fruit_name poduct guest unique_id_2 fruit_name poduct guest
92 11 apple silver Miller
93 12 cherry bronze Gus
967 121 orange purple Mike
94 176 apple silver Miller 95 banana gold John 96 orange purple Mike
100 112 cherry bronze Gus
445 111 apple silver Miller 232 apple silver Miller
355 555 cherry bronze Gus
我不确定我应该在线搜索什么才能实现这一点,非常感谢任何建议。
【问题讨论】:
-
你为什么要这样做?也许有更好的方法来解决您的主要问题
标签: python-3.x pandas python-2.7 dataframe