减少Pandas中的数据帧大小

时间:2016-12-06 01:17:09

标签: python python-2.7 pandas dataframe

我希望将pandas数据框(df)缩减为Python 2.7中的前2个值。 目前,我的数据框架是这样的:

>>> df
            test_number result  Count
21946       140063       NTV    23899
21947       140063       <9.0    1556
21948       140063       <6.0     962
21949       140063       <4.5     871
21950       140063       <7.5     764
21951       140063       <5.4     536

我希望它是这样的:

            test_number result  Count
21946       140063       NTV    23899
21947       140063       <9.0    1556

我不想限制输出,而是减少数据帧大小。

2 个答案:

答案 0 :(得分:2)

使用整数位置.iloc运算符

df.iloc[:2]

答案 1 :(得分:1)

这应该这样做

df = df.iloc[:2, :]