import numpy as np
import pandas as pd
from pandas import Series,DataFrame
import matplotlib.pyplot as plt
t_range=pd.date_range('2018-01-01','2018-12-31',freq='H') #freq:参数是隔多长时间一个间隔
print(t_range)
#进行采样
stock_df=DataFrame(index=t_range)
stock_df['BAIDU']=np.random.randint(80,160,size=len(t_range))
stock_df['ALIBABA']=np.random.randint(90,150,size=len(t_range))
print(stock_df.head())
weekly_df=DataFrame()
weekly_df['BAIDU']=stock_df['BAIDU'].resample('M').mean()
weekly_df['ALIBABA']=stock_df['ALIBABA'].resample('M').mean()
weekly_df.plot()
plt.show()
时间序列数据的采样和画图(数据处理与数据可视化的思想)
最新推荐文章于 2023-11-04 10:37:06 发布