LoginSignup
0
1

More than 3 years have passed since last update.

pandasで一分足からOHCLを作成

Last updated at Posted at 2021-04-15
import pandas as pd

filepass =  "C:/Users/aaaa/Desktop/USDJPY_M1/USDJPY_M1.csv"
date  =  pd.read_csv(filepass, sep=',',header=None,names=('day', 'open', 'high','low', 'close', 'volume'))
date['day'] = pd.to_datetime(date['day'],format='%Y.%m.%d %H:%M')#str to datetime64
df = date.set_index('day')
d_ohlc = {'open': 'first',
          'high': 'max',
          'low': 'min',
          'close': 'last',
          'volume': 'sum'}
day_df = df.resample('D').agg(d_ohlc)
day_df = day_df[day_df.index.weekday < 5]#mon==0,...,sun==6

参考:
https://note.nkmk.me/python-pandas-time-series-multiindex/
https://python.civic-apps.com/date-format/
https://note.nkmk.me/python-pandas-time-series-resample-asfreq/
https://note.nkmk.me/python-pandas-resampling-ohlc/

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1