1. 从字典创建Dataframe
>>> import pandas as pd >>> dict1 = {‘col1‘:[1,2,5,7],‘col2‘:[‘a‘,‘b‘,‘c‘,‘d‘]} >>> df = pd.DataFrame(dict1) >>> df col1 col2 0 1 a 1 2 b 2 5 c 3 7 d
2. 从多个列表创建Dataframe (先把列表转化为字典,再把字典转化为DataFrame)
>>> lista = [1,2,5,7] >>> listb = [‘a‘,‘b‘,‘c‘,‘d‘] >>> df = pd.DataFrame({‘col1‘:lista,‘col2‘:listb}) >>> df col1 col2 0 1 a 1 2 b 2 5 c 3 7 d