
上QQ阅读APP看书,第一时间看更新
012 根据日期差修改DataFrame的行标签
此案例主要演示了使用pd.DateOffset根据日期差值计算新日期,并据此在DataFrame中设置行标签。当在Jupyter Notebook中运行此案例代码之后,在DataFrame中将把日期行标签的月份数增加3个月,效果分别如图012-1和图012-2所示。

图012-1

图012-2
主要代码如下。

在上面这段代码中,df.index+=pd.DateOffset(months=3)表示在df的日期行标签中,将每个日期的月份数增加3个月,months参数表示月份差值。
此案例的主要源文件是MyCode\H789\H789.ipynb。