1

将字典转为dataframe

将字典转为dataframe(1)

使用案例:

test_dic = {'subject':[],'time':[],'name':[]}
test_dic['subject'].append('play')
test_dic['time'].append('2023:10:10')
test_dic['name'].append('jack')
test_dataframe = pd.DataFrame.from_dict(test_dic)

结果显示:

将字典转为dataframe(2)

# Import pandas package
import pandas as pd
# Define a dictionary containing employee data
data = {'Name':['Jai', 'Princi', 'Gaurav', 'Anuj'],
        'Age':[27, 24, 22, 32],
        'Address':['Delhi', 'Kanpur', 'Allahabad', 'Kannauj'],
        'Qualification':['Msc', 'MA', 'MCA', 'Phd']}
  
# Convert the dictionary into DataFrame 
df = pd.DataFrame(data)

结果显示:

posted @ 2023-05-29 21:06  Bonne_chance  阅读(73)  评论(0编辑  收藏  举报
1