怎么使用 pd,构建一对多的表格数据呢?

2022-12-05 17:54:49 +08:00
 wliansheng

请问这种使用 DataFrame 该如何实现?

1524 次点击
所在节点    Python
5 条回复
lookStupiToForce
2022-12-05 18:56:28 +08:00
two methods:

1. multi level index
intuitive but not recommended
https://pandas.pydata.org/docs/user_guide/advanced.html

2. duplicate values in first two columns to match third columns row count
Alias4ck
2022-12-06 01:59:45 +08:00
![test]( https://imgur.com/a/IdTSN4N) 不知道是不是你想要的 其实楼上也给出方案了
wliansheng
2022-12-06 10:46:55 +08:00
@lookStupiToForce
@Alias4ck 十分感谢。
craiiz
2022-12-08 14:36:33 +08:00
这个比较像透视表吧?直接 pd.pivot_table(df, index=["用户", "联系方式等信息"]) 应该就行了
wliansheng
2022-12-08 15:04:15 +08:00
@craiiz 感谢帮助,我去试试

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/900295

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX