如何使用python查找数据框中前两列的最后10行

时间:2019-06-19 10:45:26

标签: python-3.x

我想在名为index的python中访问数据帧的前两列的最后10行

index.tail(10).index.iloc[:,0:2]

但是出现以下错误:

RangeIndex' object has no attribute 'iloc

2 个答案:

答案 0 :(得分:0)

https://colab.research.google.com/drive/12fg1MpIJeVM03-DGgLr39v4D1k97bR10

import pandas as pd
df = pd.DataFrame({"datax": range(10, 64, 8), 
"datay": range(0, 84 ,12)}) # 2 columns with 7 data points

print(df) # print dataset
print(df.iloc[-2:,:1]) 
# get last two rows of the first column using iloc

您可以使用iloc在数据帧​​上执行高级索引。在我共享的Colab链接上可以找到一个示例。

答案 1 :(得分:-1)

要使用python查找数据框中前两列的最后10行,您可以使用:

df.iloc[-10:, 0:2]