构造时间序列数据集

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
import pandas as pd
import random

def generate_time_series(start_date, end_date, mean, std_dev):
dates = pd.date_range(start=start_date, end=end_date)
num_samples = len(dates)
data = [mean + random.uniform(-std_dev, std_dev) for i in range(num_samples)]
df = pd.DataFrame({
'date': dates,
'value': data
})
df.set_index('date', inplace=True)
return df

df = generate_time_series('2020-01-01', '2021-12-31', 100, 10)
print(df.head())