[英]Is there a way of unnesting a column with a list of dictionaries into a pandas Dataframe
This is how my data looks like.这就是我的数据的样子。 I tried everything from turning into a list then into a dataframe but no use.
我尝试了从变成列表到 dataframe 的所有方法,但没有用。
["[[{'uuid': '3cb5da6c-6db2-4893-9ebb-39443a7c83be', 'answers': 'Vibinators', 'votes': '74'}, {'uuid': '564b3357-df5f-4543-bd07-fa0c3c9401de', 'answers': 'I AM’s', 'votes': '139'}]]"]
solution:解决方案:
import ast
data = ["[[{'uuid': '3cb5da6c-6db2-4893-9ebb-39443a7c83be', 'answers': 'Vibinators', 'votes': '74'}, {'uuid': '564b3357-df5f-4543-bd07-fa0c3c9401de', 'answers': 'I AM’s', 'votes': '139'}]]"]
df = pd.DataFrame(ast.literal_eval(data[0])[0])
df:东风:
uuid answers votes
0 3cb5da6c-6db2-4893-9ebb-39443a7c83be Vibinators 74
1 564b3357-df5f-4543-bd07-fa0c3c9401de I AM’s 139
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.