I’m attempting to create a dataframe with dictionary keys and values in two different columns then name then name the columns with string names
Here is my dictionary:
my_dict = {'amd_0': 102, 'amd_3': 11}
Column names:
columns = ['column1', column2']
Desired output:
column1 column2
amd_0 102
amd_3 11
I tried from_dict but I’m having a hard time naming the columns. Any help is appreciated.
>Solution :
You can create a dataframe using the dictionary items and specify the columns list as the columns:
>>> df = pd.DataFrame(my_dict.items(), columns=columns)
>>> df
column1 column2
0 amd_0 102
1 amd_3 11