LoginSignup
0
0

More than 3 years have passed since last update.

3ヶ月データをずらす nヶ月データをずらす

Posted at

メモ用です.

pandasで日付・時間の列を処理(文字列変換、年月日抽出など)

import datetime
from dateutil.relativedelta import relativedelta

# 1期後を作る
df["period1"] = df["決算日"]
df_target = df[["ティッカー","period1","時価総額"]].copy()
df_target.columns = ["ティッカー","period1","period1ago"]
df_target["period1"] = df_target["period1"].dt.to_pydatetime()+ relativedelta(months=3)
df = pd.merge(df,df_target,how="inner",on=("ティッカー","period1"))
df
0
0
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
0