How to delete the last column of data of a pandas dataframe

前端 未结 8 963
耶瑟儿~
耶瑟儿~ 2021-02-02 08:52

I have some cvs data that has an empty column at the end of each row. I would like to leave it out of the import or alternatively delete it after import. My cvs data\'s have a v

相关标签:
8条回答
  • 2021-02-02 09:42

    Improve from @conner.xyz answer above:

    df.drop(df.columns[[-1,]], axis=1, inplace=True)

    If you want to delete the last two columns, replace [-1,] by [-1, -2].

    0 讨论(0)
  • 2021-02-02 09:48

    Another way to remove the last column:

    df = df[df.columns[:-1]]
    
    0 讨论(0)
提交回复
热议问题