python - Pandas 按列分组并将其他列转换为键:值对
解决方案
Try:
output = df.groupby("id").apply(lambda x: x.to_json(orient="records")[1:-1])
>>> output
id
1 {"id":1,"topic":1,"test1":"abc","test2":null,...
2 {"id":2,"topic":3,"test1":null,"test2":null,...
推荐阅读
- angular - 在primeng表的td字段中使用两个Ngfor
- django-models - Django- FCM - 如何通过 API 在数据库中创建设备?
- java - 将地图/字符串转换为 JSON
- angular - 为什么不在 stackblitz 中正确显示我的表单域
- html - 如何将 ID 属性添加到带有标签名称的标签。标签不包含任何 ID(例如:id="width-label")
- javascript - Android React Native - 无法按下 TextInput 字段
- excel - EDATE, MAXIF 闰年为去年计算
- javascript - 如何按下页面顶部的返回按钮
- php - 不要在 Wordpress 帖子类型上启动 PHP 会话
- java - 如何创建具有额外属性(例如布尔值)的关系?