Advertisement

pandas用来选取元素的方法包括loc和iloc

阅读量:

pandas库中提供了loc与iloc两种方式用于选取数据元素,而ix方法已不再建议采用

复制代码
 data = {'AAA':[4,5,6,7], 'BBB':[10,20,30,40], 'CCC':[100,50,-30, -50]}

    
 df = pd.DataFrame(data=data, index=['foo','bar','boo','kar']);df
    
    
    
    

pandas.iloc

Purely integer-location based indexing for selection by position.

.iloc[] is primarily integer position based (from 0 to length-1 of the axis), but may also be used with a boolean array.

复制代码
 #筛选第一行到第二行的数据,注意区间左闭右开

    
 df.iloc[1:3]
    
    
    
    

[pandas.loc](htt

全部评论 (0)

还没有任何评论哟~