DataFrame的创建
1.利用列表,元组构建的字典创建import pandas as pddict1 = {"流浪地球":[25,45,65,89],"唐人街探案":(89,56,89,17),"谋杀2":[19,46,49,79]}df = pd.DataFrame(dict1,index = ["第%d天"%i for i in range(1,5)])df2.利用series创建import pandas as
·
1.利用列表,元组构建的字典创建
import pandas as pd
dict1 = {"流浪地球":[25,45,65,89],"唐人街探案":(89,56,89,17),"谋杀2":[19,46,49,79]}
df = pd.DataFrame(dict1,index = ["第%d天"%i for i in range(1,5)])
df
2.利用series创建
import pandas as pd
import numpy as np
df = pd.DataFrame({"a":pd.Series(np.arange(1,6)),"b":pd.Series(np.linspace(1,6,5))})
df
3.利用字典构建的字典创建
pd.DataFrame({"甲":{"第一天":2,"第二天":5,"第三天":7},
"乙":{"第一天":1,"第二天":8,"第三天":2},
"丙":{"第一天":9,"第二天":7,"第三天":7}})
4.利用二维数组进行构建
import pandas as pd
import numpy as np
arr1 = np.arange(12).reshape(3,4)
df = pd.DataFrame(arr1)
df
5.利用字典构成的列表类构建
pd.DataFrame([{"apple":5,"banana":3,"veg":9},
{"apple":5,"banana":3,"veg":9},
{"apple":5,"banana":3,"veg":9}])
更多推荐
已为社区贡献1条内容
所有评论(0)