Home > Back-end >  how to get access of last column of a dataframe by using .loc[]?
how to get access of last column of a dataframe by using .loc[]?

Time:06-22

is it possible to get access of last column of a data frame and last row of a data frame by using

.loc[]

I saw this link

    https://stackoverflow.com/questions/40144769/how-to-select-the-last-column-of-dataframe

but in this discussion no one spoke about loc . I would be appreciate if someone helps me to to solve this problem. thanks a lot.

CodePudding user response:

` df_test = pd.DataFrame([2012, 2015, 2010], columns=['start_date'])

df_test['end_date'] = [2014, 2017, 2020]

last_index = list(df_test.index)[-1]

last_col = list(df_test.columns)[-1]

df_test.loc[last_index, last_col] `

enter image description here

CodePudding user response:

I think this will work: df.iloc[-1:,-1:]

  • Related