1
wuwukai007 2021-03-08 23:48:25 +08:00 4
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-03-08 23:54:06 +08:00
|
3
DGideas 2021-03-09 00:13:27 +08:00
上边的方法都不太好哇。。。
```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-03-09 00:15:08 +08:00
|
5
dll30 2021-03-09 21:21:50 +08:00
我愣是没看懂你想怎么转,给个说明呀
|
6
cbiqih 2021-03-10 12:27:29 +08:00
```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) ``` |