Python——DataFrame和List相互转换
目录
1 list列表转Dataframe表
——创建新列a
a = list(range(20))
print(a)
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]
——把a列表传入已有表data2
import pandas as pd
data2['b'] = pd.DataFrame(a)
2 字典转Dataframe表
data_set = [{ 'a' :['0',' 1', '2', '3' ,'4', '5'],'b':['s','d','f','g','h']}]
data = pd.DataFrame(data_set)
data
3 嵌套列表转Dataframe表
data_set = [[' 1', '2', '3' ,'4', '5'],['s','d','f','g','h']]
data = pd.DataFrame(data_set)
data