Shift the data for 3 months Shift the data for n months

For memos.

Process date / time columns with pandas (string conversion, date extraction, etc.)

import datetime
from dateutil.relativedelta import relativedelta

#Make one term later
df["period1"] = df["Settlement date"]
df_target = df[["Ticker","period1","Market capitalization"]].copy()
df_target.columns = ["Ticker","period1","period1ago"]
df_target["period1"] = df_target["period1"].dt.to_pydatetime()+ relativedelta(months=3)
df = pd.merge(df,df_target,how="inner",on=("Ticker","period1"))
df

Recommended Posts

Shift the data for 3 months Shift the data for n months
I searched for railway senryu from the data
Clean up the Cloud pak for Data deployment space
Shift the alphabet string by N characters in Python
[Understand in the shortest time] Python basics for data analysis
Deploy the strongest front-end Streamlit for data scientists on Azure!
Kaggle for the first time (kaggle ①)
Data set for machine learning
[tensorflow, keras, mnist] Take out n sheets for each label from the mnist data and create 10 * n sheets of data.
Python for Data Analysis Chapter 4
For the G test 2020 # 2 exam
Gzip the data by streaming
Kaguru for the first time
3 months note for starting Python
Python for Data Analysis Chapter 2
[PyTorch] Data Augmentation for segmentation
What is the interface for ...
Tips for data analysis ・ Notes
Python for Data Analysis Chapter 3
Studying web scraping for the purpose of extracting data from Filmarks # 2
Seaborn basics for beginners ① Aggregate graph of the number of data (Countplot)