New here and new to newish to Python. I've been spinning my wheels for the better part of a week and I am not getting the results I expect. I have the historic 1 min trade data in csv with labeled columns of datetime, price, and volume. Like below:
datetime price volume
0 2013-10-07 20:50:30 123.61 0.100000
1 2013-10-08 02:58:35 123.91 1.000000
But I'd like it to read out exactly as below this was from Huobi's (and Binance) 1-min candles t,o,h,l,c,v pulled from ccxt:
t o h l c v
0 2017-10-27 00:00:00+00:00 5869.70 5869.70 5869.70 5869.70 0.985300
1 2017-10-27 00:01:00+00:00 5869.70 5869.70 5869.70 5869.70 0.000000
import pandas as pd
# Load data into a DataFrame from CSV
**# This line here after loading the DataFrame is where I'm lost**
# Resample the DataFrame to 1-minute intervals and calculate the open, high, low, and close prices and volume
candles = df.resample('1T').agg({'price': ['first', 'max', 'min', 'last'], 'volume': 'sum'})
candles.columns = ['o', 'h', 'l', 'c', 'v']
print(candles)
Thanks for helping possibly point this in the right direction.
Time (t) is now the index and it's shift down a row. I expected 0,1 etc. and o,h,l has no data.
o h l c v
t
2013-10-07 20:50:30 NaN NaN NaN 123.61 0.100000
2013-10-08 02:58:35 NaN NaN NaN 123.91 1.000000
Like this format:
t o h l c v
0 2017-10-27 00:00:00+00:00 5869.70 5869.70 5869.70 5869.70 0.985300
1 2017-10-27 00:01:00+00:00 5869.70 5869.70 5869.70 5869.70 0.000000