snub-fighter
snub-fighter

Reputation: 171

Pandas | Save Index Value of last row

Trying to find the last index value and save to variable but I cant seem to pull only the index column alone. I want to be able to use the date to determine if new values have been generated.

Process is as follows:

  1. Parse excel for latest (last) date
  2. Save latest (last) date to variable
  3. Continue to monitor for new entries and save latest (last) to that variable again.

df = pd.read_csv('USDT_XRP_4HOUR_JAN_2017.csv', index_col='date',delimiter=',') print('INDEX - LAST 1 LINES') print(df.iloc[-1:,-1]) print('END OF INDEX - LAST 1 LINES')

OUTPUT

END OF INDEX - LAST 1 LINES date 2018-09-18 10:55:00 0.274509 Name: high, dtype: float64 END OF INDEX - LAST 1 LINES

Upvotes: 1

Views: 2325

Answers (1)

Abhinav Upadhyay
Abhinav Upadhyay

Reputation: 2585

You access the index by the index attribute of the dataframe. To get the last value, you could do this

df.index[-1]

or

df.index.values[-1]

Upvotes: 2

Related Questions