如何在.xlsx中删除重复项并用熊猫将值移至新列
我的.xlsx表有多个条目: 条目
我尝试实现的目标: 结果
因此,我真的被卡住了。我尝试过df.drop_duplicates()
,但无济于事。 如果您可以分享一些想法或在哪里看,那就太好了! Tia
P.S.对不起,图片,但由于某种原因,它无法正确渲染。
I have .xlsx sheet with multiple entries:
Entries
what I try to achieve:
result
Therefore I am really stuck. I have tried df.drop_duplicates()
but it does not help.
If you could share some ideas or where to look it would be awesome!
TIA
P.S. sorry for the pictures, but it does not render correctly for some reason.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我的策略是创建然后将索引设置为
触发
列连接2个数据范围。一个数据帧仅包含触发
, to 和 列的代码>类别
和说明
列。这里的“窍门”是使用 dataframe。 Pivot 将相应的类别
和descript
值中的值添加到自己的列中。为了使其更容易理解,以下是每个步骤之后的数据框:
My strategy was to create and then join 2 dataframes with the index set to the
Trigger
column. One dataframe contains only theTrigger
,To
, andFrom
columns, while the other dataframe has theTrigger
,Category
, andDescription
columns. The "trick" here is to use DataFrame.pivot to get the correspondingCategory
andDescription
values into their own columns.To make it easier to understand, here are the dataframes after each step: