我有一本字典如下:
d = {("Sam","Scotland","23") : 25,
("Oli","England","23") : 28,
("Ethan","Wales","18") : 19}
我想将它转换成一个如下所示的 Pandas 数据框:
Name Country Age Count
Sam Scotland 23 25
Oli England 23 28
Ethan Wales 18 19
我试着这样做:
df = pd.DataFrame.from_items(d.items(),orient="index",
columns=["Name","Country","Age","Count"])
但我收到此错误:
ValueError: The value in each (key, value) pair must be an array, Series, or dict
我很欣赏通过循环遍历元组的每个项目和每个元素是可能的,但是有没有更干净的方法来做到这一点?
Qyouu
相关分类