import pandas as pd
from datetime import datetime
fn='s-p-tsx-60-futures_01.csv'
sp=pd.read_csv(fn)
sp=sp.rename(columns={' value':'value'})
sp['date']=pd.to_datetime(sp.date)
sp['Year']=pd.DatetimeIndex(sp['date']).year
sp['Month']=pd.DatetimeIndex(sp['date']).month
sp['dayofweek']=sp['date'].dt.dayofweek
sp['dayofmonth']=pd.DatetimeIndex(sp['date']).day
sp['dayofyear']=pd.DatetimeIndex(sp['date']).dayofyear
sp.tail(5)
date value Year Month dayofweek dayofmonth dayofyear
5176 2020-04-23 857.4 2020 4 3 23 114
5177 2020-04-24 868.7 2020 4 4 24 115
5178 2020-04-27 879.7 2020 4 0 27 118
5179 2020-04-28 888.5 2020 4 1 28 119
5180 2020-04-29 915.5 2020 4 2 29 120
import pandas as pd
fn='s-p-tsx-60-futures_01.csv'
df=pd.read_csv(fn)
df['date']=df['date'].astype('datetime64[ns]')
df['timezone']=df.date.dt.tz
df['Year']=df.date.dt.year
df['is_leap_year']=df.date.dt.is_leap_year
df['Month']=df.date.dt.month
df['Month_name']=df.date.dt.month_name()
df['days_in_month']=df.date.dt.days_in_month
df['daysinmonth']=df.date.dt.daysinmonth
df['monthday']=df.date.dt.day
df['yearday']=df.date.dt.dayofyear
df['is_month_start']=df.date.dt.is_month_start
df['is_month_end']=df.date.dt.is_month_end
df['is_year_start']=df.date.dt.is_year_start
df['is_year_end']=df.date.dt.is_year_end
df['hour']=df.date.dt.hour
df['minute']=df.date.dt.minute
df['second']=df.date.dt.second
df['weekday']=df.date.dt.weekday
df['weekday_name']=df.date.dt.weekday_name
df['quarter']=df.date.dt.quarter
df['is_quarter_start']=df.date.dt.is_quarter_start
df['is_quarter_end']=df.date.dt.is_quarter_end
df['freq']=df.date.dt.freq
df.head(5)
Like this:
Like Loading...