import pandas as pd
Series
类似于一维数组的对象
t=pd.Series([1,2,3,4,5]) print(t) ''' 0 1 1 2 2 3 3 4 4 5 dtype: int64 '''
t=pd.Series([1,2,3,4,5],index=['a','b','c','d','e']) print(t) ''' a 1 b 2 c 3 d 4 e 5 dtype: int64 '''
import pandas as pd d={'a':1,'b':2,'c':3,'d':4,'e':5} t=pd.Series(d) print(t) ''' a 1 b 2 c 3 d 4 e 5 dtype: int64 '''
DataFrame
表格型的结构,类似于R语言中的数据框
d=[['wangfei',12,'f'],['nihao',23,'f'],['zhangwei',12,'m']] t=pd.DataFrame(d,index=[0,1,2],columns=['name','age','sex']) print(t) ''' name age sex 0 wangfei nihao zhangwei 1 12 23 12 2 f f m [3 rows x 3 columns] '''
#嵌套字典 d={'name':{0:'wangfei',1:'nihao',2:'zhangwei'},'age':{0:12,1:23,2:12},'sex':{0:'f',1:'f',2:'m'}} #外层字典的键作为列,内层字典的键作为行索引 t=pd.DataFrame(d) print(t) ''' age name sex 0 12 wangfei f 1 23 nihao f 2 12 zhangwei m [3 rows x 3 columns] '''