pandas) dictionary to pandas dataframe

boingboing·2023년 4월 27일
0
import pandas as pd

# create the dictionary
new_dict = {'apple':5, 'banana':3, 'cat':5}

# convert dictionary to dataframe
df = pd.DataFrame.from_dict(new_dict, orient='index', columns=['count'])

# print dataframe
print(df)
  • We set the orient parameter to 'index', which indicates that the keys of the dictionary should be used as the row labels in the resulting DataFrame.

  • We also specify the columns parameter to create a new column called 'count' in the DataFrame, which will contain the values from the original dictionary.

0개의 댓글