# 先创建一个DataFrame对象
import pandas as pd
data = [[1,2,3],[4,5,6]]
index = ['0','1']
columns=['a','b','c']
df = pd.DataFrame(data=data, index=index, columns=columns)
# 数据展示
a b c
0 1 2 3
1 4 5 6
index 和 columns 都是字符串作为label
df.loc[:'1','a':'b']
df.iloc[:2,0:2]
# 查询出的数据是一样的
a b
0 1 2
1 4 5
# 区别:
# loc只能使用标签索引如'1' 'a' 'b',不能使用整数索引,通过标签索引进行查询时,前闭后闭包括也就是包括'1'行
# iloc只能使用整数索引如 2 0 2,不能使用标签索引,通过整数索引进行查询时,前闭后开也就是不包括下标为2的行。