# -*- coding: utf-8 -*-# Time : 2016/11/28 15:14# Author : XiaoDeng# version : python3.5# Software: PyCharm Community Editionimport pandas as pdimport numpy as npimport matplotlib.pyplot as pltobj=pd.Series(np.arange(4.),index=['a','b','c','d'])# print(obj)"""a 0.0b 1.0c 2.0d 3.0dtype: float64"""#索引用法print(obj['a'])print(obj[1])#索引之切片用法print('----'*5)print(obj[2:4])print(obj[['a','b']])#取特定索引,可以不连续的索引print('----'*5)print(obj[[1,3]])#取索引小于2个数据print(obj[obj<2])
# -*- coding: utf-8 -*-# Time : 2016/11/28 15:14# Author : XiaoDeng# version : python3.5# Software: PyCharm Community Editionimport pandas as pdimport numpy as npimport matplotlib.pyplot as pltdata=pd.DataFrame(np.arange(16).reshape(4,4),index=['ohio','colorado','utah','newyork'],columns=['one','two','three','four'])print(data)#索引基本用法print('----'*5)print(data['two'])print('----'*5)print(data[['two','one']])#索引方式print('----'*5)print(data[0:2])#类似条件语句方式#查找two列数据大于5的所有数据print('----'*5)print(data[data['two']>5])#对data中所有值小于5的值,重新统一赋值为0print('----'*5)data[data<5]=0print(data)""" one two three fourohio 0 0 0 0colorado 0 5 6 7utah 8 9 10 11newyork 12 13 14 15"""#对行和列同时索引/# data.ix[行索引名,[列名,列名]]print('----'*5)print(data.ix['colorado',['two','four']])"""two 5four 7Name: colorado, dtype: int32"""print('----'*5)# data.ix[[行索引名,行索引名],[列索引,列索引,列索引]]s=data.ix[['colorado','ohio'],[3,0,1]]print(s)""" four one twocolorado 7 0 5ohio 0 0 0"""print('----'*5)print(data.ix[2]) #行索引,索引为2个数据print(data)print('----'*5)# 行索引取utah前的行,列取two列的数据//print(data.ix[:'utah','two'])#同时满足2个条件#1、data.three>5的数据#2、列索引2之前的数据#3、如此形成数据的交叉print('----'*5)print(data.ix[data.three>5,:2])