series是一维,那么如何构建多维数据?
这就涉及到了dataframe,首先需要了解dataframe(可自行百度)以及建立dataframe.
当前建立dataframe的方式有三种:字典创建;列表嵌套创建;数组创建(涉及numpy)
1.字典创建
import pandas as pd
data={'name':['A','B','C','D'],
'score':[20,30,40,50],
'CITY':['WW','DD','DW','SW']}
W=pd.DataFrame(data)
W
代码运行结果如下
2。列表嵌套创建
import pandas as pd
#列表嵌套列表
data1=[['A',20,'WW'],
['B',30,'DD'],
['C',40,'DW'],
['D',50,'SW']]
W1=pd.DataFrame(data1,columns=['name','score','CITY'])
W1
#列表嵌套元组
import pandas as pd
data1=[('A',20,'WW'),
('B',30,'DD'),
('C',40,'DW'),
('D',50,'SW')]
W2=pd.DataFrame(data1,columns=['name','score','CITY'])
W2
3.数组创建
import pandas as pd
import numpy as np
data2=np.array([['A',20,'WW'],
['B',30,'DD'],
['C',40,'DW'],
['D',50,'SW']])
W2=pd.DataFrame(data2,columns=['name','score','CITY'])
W2
运行结果