I have a dictionary as follows:
d = {("Sam","Scotland","23") : 25,
("Oli","England","23") : 28,
("Ethan","Wales","18") : 19}
I would like to convert it into a pandas data frame which would look like this:
Name Country Age Count
Sam Scotland 23 25
Oli England 23 28
Ethan Wales 18 19
I tried to do it like this:
df = pd.DataFrame.from_items(d.items(),orient="index",
columns=["Name","Country","Age","Count"])
But I get this error:
ValueError: The value in each (key, value) pair must be an array, Series, or dict
I appreciate that it would be possible by looping through each item and each element of the tuple, but is there a cleaner way to do it?