close

How to select the last column of dataframe

Hello Guys, How are you all? Hope You all Are Fine. Today We Are Going To learn about How to select the last column of dataframe in Python. So Here I am Explain to you all the possible Methods here.

Without wasting your time, Let’s start This Article.

Table of Contents

How to select the last column of dataframe?

  1. How to select the last column of dataframe?

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

  2. select the last column of dataframe

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

Method 1

Use iloc and select all rows (:) against the last column (-1):

df.iloc[:,-1:]

Method 2

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]]

Summery

It’s all About this issue. Hope all Methods helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which Method worked for you? Thank You.

Also, Read