loc中的数据是列名,是字符串,所以前后都要取;iloc中数据是int整型,所以是Python默认的前闭后开
df
0 1 2 3
0 green M 10.1 class1
1 red L 13.5 class2
2 blue XL 15.3 class1
In[10]: df.loc[0:1] #取第一和第二行,loc[]中的数字其实是行索引,所以算是前闭加后闭
Out[10]:
0 1 2 3
0 green M 10.1 class1
1 red L 13.5 class2
正确
data.loc[:,'month_release'],data.iloc[;,1:5]对
错误:loc是标签,而iloc必须是序号
data.iloc[:,'month_release']错
data=data[data['month_release']>='2019-01']