Although this question has a duplicate ( Python Dictionary for Pandas Dataframe ), I find that there is a simpler answer than the ones provided there.
Convert values ββto lists:
d = {'id': ['CS2_056'], 'cost': [2], 'name': ['Tap']}
then just:
df = pd.DataFrame(d) print(df) # cost id name # 0 2 CS2_056 Tap
Keep in mind that if the value of the columns is set, you still need to explicitly point the columns
to the DataFrame
:
df = pd.DataFrame(d, columns=['id', 'cost', 'name']) print(df) # id cost name # 0 CS2_056 2 Tap
source share