CSV file. df
before resample and after applying:
df["dateandtime"] = (pd.to_datetime(df.pop("DATE").str.cat(df.pop("TIME"), sep=" ")))
df = df.set_index(pd.DatetimeIndex(df.pop("dateandtime")))
dateandtime | Open | High | Low | Close | VOLUME |
---|---|---|---|---|---|
2020-03-11 00:00:00-04:00 | 2812.75 | 2813.25 | 2811.25 | 2811.25 | 296 |
2020-03-11 00:01:00-04:00 | 2811.25 | 2811.5 | 2809.25 | 2809.5 | 359 |
2020-03-11 00:02:00-04:00 | 2809.25 | 2810 | 2808.25 | 2809.5 | 189 |
2020-03-11 00:03:00-04:00 | 2809.5 | 2809.5 | 2806.5 | 2806.75 | 602 |
2020-03-11 00:04:00-04:00 | 2806.5 | 2809.75 | 2806.5 | 2809 | 299 |
How do I resample this 1 minute candlestick data into 15 minute data? I tried:
from dateutil.tz import gettz
import pandas as pd
import finplot as fpltdf = pd.read_csv('/home/user/Documents/finance/fin-smart/lab/ES.csv')
df.rename(columns={'OPEN': 'Open'}, inplace=True)
df.rename(columns={'HIGH': 'High'}, inplace=True)
df.rename(columns={'LOW': 'Low'}, inplace=True)
df.rename(columns={'CLOSE': 'Close'}, inplace=True)
df["dateandtime"] = (pd.to_datetime(df.pop("DATE").str.cat(df.pop("TIME"), sep=" ")))
df = df.set_index(pd.DatetimeIndex(df.pop("dateandtime")))# first day is 2010.01.04
# last day is 2020.03.13
start_date = '2020.03.12'
end_date = '2020.03.13'
df = df.loc[start_date:end_date]df.resample("15T").agg(Open=("Open", "first"),High=("High", "max"),Low=("Low", "min"),Close=("Close", "last"),
)fplt.display_timezone = gettz('America/Chicago')
fplt.candlestick_ochl(df[['Open', 'Close', 'High', 'Low']])
fplt.show()
It gives the same output as without df.resample()
and no error or warning. Is df
in an incorrect format?