In [1]:
import pandas as pd
import datetime
In [2]:
df = pd.read_csv('data/src/sample_datetime_multi.csv')
In [3]:
print(df)
In [4]:
print(df.dtypes)
In [5]:
print(type(df['A'][0]))
In [6]:
print(pd.to_datetime(df['A']))
In [7]:
print(pd.to_datetime(df['B'], format='%Y年%m月%d日 %H時%M分'))
In [8]:
print(pd.to_datetime(df['A']) == pd.to_datetime(df['B'], format='%Y年%m月%d日 %H時%M分'))
In [9]:
df['X'] = pd.to_datetime(df['A'])
In [10]:
print(df)
In [11]:
print(df.dtypes)
In [12]:
print(df['X'][0])
In [13]:
print(type(df['X'][0]))
In [14]:
print(issubclass(pd.Timestamp, datetime.datetime))
In [15]:
print(df['X'][0].year)
In [16]:
print(df['X'][0].weekday_name)
In [17]:
py_dt = df['X'][0].to_pydatetime()
print(type(py_dt))
In [18]:
dt64 = df['X'][0].to_datetime64()
print(type(dt64))
In [19]:
print(df['X'][0].timestamp())
In [20]:
print(pd.to_datetime('1970-01-01 00:00:00').timestamp())
In [21]:
print(int(df['X'][0].timestamp()))
In [22]:
print(df['X'][0].strftime('%Y/%m/%d'))
In [23]:
print(df['X'].dt.year)
In [24]:
print(df['X'].dt.hour)
In [25]:
print(df['X'].dt.dayofweek)
In [26]:
print(df[df['X'].dt.dayofweek == 4])
In [27]:
print(df['X'].astype(str))
In [28]:
print(df['X'].dt.strftime('%A, %B %d, %Y'))
In [29]:
print(df['X'].dt.strftime('%Y年%m月%d日'))
In [30]:
df['en'] = df['X'].dt.strftime('%A, %B %d, %Y')
df['jp'] = df['X'].dt.strftime('%Y年%m月%d日')
In [31]:
print(df)
In [32]:
print(df['X'].dt.to_pydatetime())
In [33]:
print(type(df['X'].dt.to_pydatetime()))
print(type(df['X'].dt.to_pydatetime()[0]))
In [34]:
print(df['X'].values)
In [35]:
print(type(df['X'].values))
print(type(df['X'].values[0]))
In [36]:
print(df['X'].map(pd.Timestamp.timestamp))
In [37]:
print(df['X'].map(pd.Timestamp.timestamp).astype(int))
In [38]:
df_i = df.set_index('X').drop(['en', 'jp'], axis=1)
In [39]:
print(df_i)
In [40]:
print(df_i.index)
In [41]:
print(df_i.index.minute)
In [42]:
print(df_i.index.strftime('%y/%m/%d'))
In [43]:
df_i['min'] = df_i.index.minute
df_i['str'] = df_i.index.strftime('%y/%m/%d')
In [44]:
print(df_i)
In [45]:
df_csv = pd.read_csv('data/src/sample_datetime_multi.csv', parse_dates=[0])
In [46]:
print(df_csv)
In [47]:
print(df_csv.dtypes)
In [48]:
df_csv_jp = pd.read_csv('data/src/sample_datetime_multi.csv',
parse_dates=[1],
date_parser=lambda date: pd.to_datetime(date, format='%Y年%m月%d日 %H時%M分'))
In [49]:
print(df_csv_jp)
In [50]:
print(df_csv_jp.dtypes)
In [51]:
df_csv_jp_i = pd.read_csv('data/src/sample_datetime_multi.csv',
index_col=1,
parse_dates=True,
date_parser=lambda date: pd.to_datetime(date, format='%Y年%m月%d日 %H時%M分'))
In [52]:
print(df_csv_jp_i)
In [53]:
print(df_csv_jp_i.index)