1
wuwukai007 2021 年 3 月 8 日 import pandas as pd
from pandas.io.json import json_normalize json_normalize(a,'tags',['userid']).drop('type',axis=1).to_dict('records') 如果觉得有用,请务必回复我,不然我会伤心的😥 |
2
Macv1994 2021 年 3 月 8 日
|
3
DGideas 2021 年 3 月 9 日
上边的方法都不太好哇。。。
```python a = [ {"userid":"Change","tags":[{"type":1,"tag_id":"e" }],}, {"userid":"andy.lei","tags":[{"type":1,"tag_id":"eg" },{"type":1,"tag_id":"ti"}],} ] result = [] [*map(lambda x: result.extend([{"userid": x["userid"], "tagid": tag["tag_id"]} for tag in x["tags"]]), a)] print(result) ``` |
4
DGideas 2021 年 3 月 9 日
|
5
dll30 2021 年 3 月 9 日
我愣是没看懂你想怎么转,给个说明呀
|
6
cbiqih 2021 年 3 月 10 日
```python
users = [ {"userid": "Change", "tags": [{"type": 1, "tag_id": "e"}], }, {"userid": "andy.lei", "tags": [{"type": 1, "tag_id": "eg"}, {"type": 1, "tag_id": "ti"}], } ] result = [{'userid': user['userid'], 'tagid': tag['tag_id']} for user in users for tag in user['tags']] print(result) ``` |