LoginSignup
0
2

More than 3 years have passed since last update.

pythonで時間データの処理

Posted at

pythonで時間データを1時間ごとにまとめたい

下準備

import datetime

文字列からdatetimeに①


data['datetime']=datetime.datetime(data['datetime'])

文字列からdatetimeに②


data['datetime']=pd.to_datetime(data['datetime'])

何時か?を取り出す。


data['hour']=data['datetime'].dt.hour

datetimeをtimeに


data['time']=data['datetime'].dt.time

timeに日時(dt1)を加えてdatetimeにする


d1 = datetime.date(year=1, month=1, day=1)
datetime.datetime.combine( d1,data['time'][0])

一時間ごとに区切って数がわかる。


data.groupby(pd.Grouper(key='datetime', freq='1h')).groups

参考

pandasで日付・時間の列を処理(文字列変換、年月日抽出など)
Pythonで経過時間や日時(日付・時刻)の差分を測定・算出
dtの使い方

0
2
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
2