下面是一份示例代码,可以根据实际情况调整:
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
plot_df = pd.DataFrame(index=pd.date_range(start="20200101", periods=200, freq="D"), columns=['line'])
plot_df.loc[plot_df.index[0], 'line'] = 0 # 把第一个值设置为0
for sample_index in plot_df.sample(6).index: # 随机选择6个值,填充
plot_df.loc[sample_index, 'line'] = np.random.randint(10)
plot_df.fillna(method='pad', inplace=True) # 借助缺失值填充来补全所有的值
plot_df.plot() # 绘图看一下效果
plt.show()
效果图如下:



