Pandas Series 对象的loc与iloc区别

import pandas as pd
temp = pd.Series([1,2,3,4,5])

loc用法:
temp.loc[0:3]
0 1
1 2
2 3
3 4
# 输出索引为0-3的值(基于索引)
temp.loc[-1]  报错

iloc用法:
temp.iloc[0:3]
0 1
1 2
2 3
#输出前三个值(基于位置)
temp.iloc[-1]
5

 

posted @ 2019-11-07 10:30  没有显示名称  阅读(710)  评论(0编辑  收藏  举报