Last active
July 15, 2020 08:26
-
-
Save gautierdag/7007e666cd43f3aef15dc406120bf652 to your computer and use it in GitHub Desktop.
Generating a random series
This file contains 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
from random import randint | |
import pandas as pd | |
num_observations = 500 | |
dates = pd.to_datetime([f"{randint(2018, 2020)}-{randint(1, 12)}-{randint(1, 27)}" | |
for _ in range(num_observations)]).unique() | |
df = pd.DataFrame({"date": dates, | |
"balance": [randint(0, 10000) | |
for _ in range(len(dates))] | |
}) | |
df = df.set_index("date").resample("H").ffill().reset_index() | |
print(f"Resampling has expanded our df from {len(dates)} rows to {len(df)}!") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment