【发布时间】:2016-09-20 09:50:53
【问题描述】:
我正在用 pandas 数据框绘制一些时间序列,但我遇到了周末出现间隙的问题。我能做些什么来消除时间序列图中的空白?
date_concat = pd.to_datetime(pd.Series(df.index),infer_datetime_format=True)
pca_factors.index = date_concat
pca_colnames = ['Outright', 'Curve', 'Convexity']
pca_factors.columns = pca_colnames
fig,axes = plt.subplots(2)
pca_factors.Curve.plot(ax=axes[0]); axes[0].set_title('Curve')
pca_factors.Convexity.plot(ax=axes[1]); axes[1].set_title('Convexity'); plt.axhline(linewidth=2, color = 'g')
fig.tight_layout()
fig.savefig('convexity.png')
理想情况下,我希望时间序列只显示工作日而忽略周末。
【问题讨论】:
-
您只是想在周末截断数据/行吗?
-
是的,但是我没有专门的周末数据...当我将日期转换为日期时间格式时,它人为地创建了周末...
-
我认为它没有添加任何数据,它只是试图保持比率并简单地将周五的点连接到周一的点。也许你想要一个条形图?
-
有没有办法在不显示周末造成的差距的情况下连接周五和周一之间的点?
-
您可以尝试:
pca_factors.reset_index().Convexity.plot()然后您需要以某种方式手动放置所需的 x-ticklabels...
标签: python pandas matplotlib dataframe