I have a dataframe and each record stores a list of dictionaries like this:
row prodect_id recommend_info
0 XQ002 [{"recommend_key":"XXX567","recommend_point":50},
{"recommend_key":"XXX236","recommend_point":20},
{"recommend_key":"XXX090","recommend_point":35}]
1 XQ003 [{"recommend_key":"XXX089","recommend_point":30},
{"recommend_key":"XXX567","recommend_point":20}]
I would like to flatten lists of dictionaries, so that it will look like this
row prodect_id recommend_info_recommend_key recommend_info_recommend_point
0 XQ002 XXX567 50
1 XQ002 XXX236 20
2 XQ002 XXX090 35
3 XQ003 XXX089 30
4 XQ003 XXX567 20
I know how to convert only one list of dictionaries to a dataframe. like this:
d = [{"recommend_key":"XXX089","recommend_point":30},
{"recommend_key":"XXX567","recommend_point":20}]
df = pd.DataFrame(d)
row recommend_key recommend_point
0 XXX089 30
1 XXX567 20
But I don't know how to do this to a dataframe when there is one column storing list of dicts, or there are multiple columns storing list of dicts
row col_a col_b col_c
0 B001 [{"a":"b"},{"a":"c"}] [{"y":11},{"a":"c"}]
1 D009 [{"c":"o"},{"g":"c"}] [{"y":11},{"a":"c"},{"l":"c"}]
2 G068 [{"c":"b"},{"a":"c"}] [{"a":56},{"d":"c"}]
3 C004 [{"d":"a"},{"b":"c"}] [{"c":22},{"a":"c"},{"b":"c"}]
4 F011 [{"h":"u"},{"d":"c"}] [{"h":27},{"d":"c"}]