How to select the last column of dataframe

后端 未结 7 783
北恋
北恋 2020-11-30 01:18

I have done some searching for the answer to this question, but all I can figure out is this:

df[df.columns[len(df.columns)-1]]

which to m

7条回答
  •  被撕碎了的回忆
    2020-11-30 02:13

    Somewhat similar to your original attempt, but more Pythonic, is to use Python's standard negative-indexing convention to count backwards from the end:

    df[df.columns[-1]]
    

提交回复
热议问题