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 me seems unweildy, and un-pythonic (and slow?).
What is the easiest way to select the data for the last column in a pandas dataframe without specifying the name of the column?
To select all columns except one column in Pandas DataFrame, we can use df. loc[:, df. columns != <column name>].
Select & print last row of dataframe using tail() It will return the last row of dataframe as a dataframe object. Using the tail() function, we fetched the last row of dataframe as a dataframe and then just printed it.
Use iloc and select all rows (:
) against the last column (-1
):
df.iloc[:,-1:]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With