一、Series一维的数据结构
s1=pd.Series(data=np.array(【1,2,3】),index=【'a','b','c'】)
注:data是传入的数据 index表示的索引
二、DataFrame(二维的、表格型的数据结构)
s1=pd.DataFrame(data=np.arange(12).reshape(3,4),index=【'a','b','c','d'】,columns=【'q','w','e','r'】)
(1)增加数据
可以通过给列索引或者列名称赋值的方式实现
s1【't'】=【1,2,3】
(2)删除数据
del s1【'q'】
s1.drop('w',axis=1)
三、取行
s1.loc【【'a','b'】】
s1.iloc【【0,2】】
用切片的方式取行
s1.iloc【0:3】
四、取列
s1【'q'】
s1【【'q','e'】】
s1.loc【:,'q'】
s1.iloc【:,【0,1】】
s1.loc【:,【'q','e'】】
s1.iloc【0:2,【0,1】】
s1.loc【:,'q':'r'】
五、索引
索引对象:Pandas中的索引都是Index类对象,又称为索引对象,该对象是不可以进行修改的,以保障数据的安全
重置索引:Pandas中提供了一个重要的方法是reindex(),该方法的作用是对原索引和新索引进行匹配,也就是说,新索引含有原索引的数据,而原索引数据按照新索引排序
reindex()方法的语法格式如下:
DataFrame.reindex(labels = None,index = None,
columns = None,axis = None,method = None, copy = True,level = None,fill_value = nan,limit = None,tolerance = None )