Last active
December 15, 2020 06:45
-
-
Save hotohoto/79860b0a762bb37098407d59ac5f8e67 to your computer and use it in GitHub Desktop.
Downsample a time-series dataset
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
import numpy as np | |
input_csv = "./weather_history_weekly.csv" | |
output_csv_2w = "./weather_history_2w.csv" | |
output_csv_monthly = "./weather_history_monthly.csv" | |
df = pd.read_csv(input_csv) | |
N = len(df) | |
all_columns = df.columns | |
df["Datetime"] = pd.to_datetime(df["Datetime"]) | |
df.resample("2W", on="Datetime").mean().to_csv(output_csv_2w) | |
df.resample("1M", on="Datetime").mean().to_csv(output_csv_monthly) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment