dataframe是一张二维表,行(索引),列(标签)
import numpy as np import pandas as pd test_array=np.arange(16).reshape(4,4)#四行四列数值到16的数组 test1=pd.DataFrame(test_array,index=['One','Two','Three',"Four"],columns=['a','b','c','d']) '''loc''' test1.loc['One']#读取one行数据 test1.loc['One','a':'c']#读取one行数据中a到c列 test1.loc['One':'Three','a':'c']#读取one-Three行数据中a到c列 test1.loc[['One','Three'],'a':'c']#读取one和Three行数据中a到c列 '''iloc''' test1.iloc[0]#读取One行数据 test1.iloc[0,0:3]#读取one行数据中a到c列 test1.iloc[0:3,0:3]#读取one-Three行数据中a到c列 test1.iloc[[0,2],0:3]#读取one和Three行数据中a到c列