Pandas resample ohlc, how to extract only Open, High, Close values

I've following code to calculate ohlc data. When I print, it shows date and other data. I'm interested in only close value. Any help on this, I've searched everywhere but unable to find.

df = pd.read_csv('data.csv', names=['last_price','date'],index_col=1,parse_dates=True)
df = pd.DataFrame(df)
data = df['last_price'].resample('5min').ohlc()
print (data['close'])

2021-07-08 07:25:00 15877.65
Freq: 5T, Name: close, dtype: float64

I'm interested in only print 15877.65
  • tahseen
    tahseen edited July 10
    If you are having only one symbol then use

    data = df['last_price'].resample("5T").ohlc()

    If you have more than one symbol then you have to first group by symbols and then apply above
  • msangani
    Thank you for your response. It still prints other values as well. Please note I'm interested in only retrieving 15838 value. I'm not that familiar with pandas, so all learnings are from the web.

    2021-07-08 11:25:00 15838.0
    Freq: 5T, Name: close, dtype: float64

    My input file (data.csv):
    15837.75,2021-07-08 11:29:28
    15837.9,2021-07-08 11:29:29
    15838.0,2021-07-08 11:29:30
  • tahseen
    If for a particular row then use below

    print (data['close'].values[0])
  • msangani
    msangani edited July 13
    Thank you so much tahseen. It was so simple, but I was unable to figure out. Didn't realise it was array.

    Thank you once again.
Sign In or Register to comment.