Selecting last n columns and excluding last n columns in dataframe

前端 未结 3 489
深忆病人
深忆病人 2020-12-05 14:01

How do I:

  1. Select last 3 columns in a dataframe and create a new dataframe?

I tried:

y = dataframe.iloc[:,-3:]
3条回答
  •  情深已故
    2020-12-05 14:46

    The most efficient way:

    1. Select last n columns

    df1 = df.iloc[:,-n:]

    2. Exclude last n columns

    df1 = df.iloc[:,:-n]

提交回复
热议问题