Skip to content

Instantly share code, notes, and snippets.

@GurjotSinghMahi
Created February 18, 2021 14:05
Show Gist options
  • Save GurjotSinghMahi/79ddc80466f140c0bb8c649569d08a87 to your computer and use it in GitHub Desktop.
Save GurjotSinghMahi/79ddc80466f140c0bb8c649569d08a87 to your computer and use it in GitHub Desktop.
# Increase Date to days, months and years
df['original_date'] = df['Date']
# increase date by 1
df['increase_date'] = df['Date'] + pd.tseries.offsets.DateOffset(days=1)
# increase date by 3 month
df['increase_month'] = df['Date'] + pd.tseries.offsets.DateOffset(months=3)
# increase date by 2 year
df['increase_year'] = df['Date'] + pd.tseries.offsets.DateOffset(years=2)
# Remove time and keep date only
df['increase_date'] = pd.to_datetime(df['increase_date']).dt.date
df['increase_month'] = pd.to_datetime(df['increase_month']).dt.date
df['increase_year'] = pd.to_datetime(df['increase_year']).dt.date
# Print the dataframe
print(tabulate(df[['original_date', 'increase_date', 'increase_month', 'increase_year']], headers = 'keys', tablefmt = 'psql'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment