Delete the first three rows of a dataframe in pandas

后端 未结 7 1380
鱼传尺愫
鱼传尺愫 2020-12-07 08:58

I need to delete the first three rows of a dataframe in pandas.

I know df.ix[:-1] would remove the last row, but I can\'t figure out how to remove first

7条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-07 09:27

    I think a more explicit way of doing this is to use drop.

    The syntax is:

    df.drop(label)
    

    And as pointed out by @tim and @ChaimG, this can be done in-place:

    df.drop(label, inplace=True)
    

    One way of implementing this could be:

    df.drop(df.index[:3], inplace=True)
    

    And another "in place" use:

    df.drop(df.head(3).index, inplace=True)
    

提交回复
热议问题