首页 > 解决方案 > 如何创建趋势线日期与数据(百分比值)

问题描述

导入excel后我有数据框

Date    Inflation Rate
1-Jan   0.26
2-Jan   0.3
3-Jan   0.29
4-Jan   0.29
5-Jan   0.29
6-Jan   0.29
7-Jan   0.28
8-Jan   0.28
9-Jan   0.28
10-Jan  0.27
11-Jan  0.28
12-Jan  0.28
13-Jan  0.27
14-Jan  0.28
15-Jan  0.27
16-Jan  0.27
17-Jan  0.27
18-Jan  0.27
19-Jan  0.24
20-Jan  0.26
21-Jan  0.26
22-Jan  0.26
23-Jan  0.26
24-Jan  0.25
25-Jan  0.24
26-Jan  0.22
27-Jan  0.21
28-Jan  0.19
29-Jan  0.18
30-Jan  0.19

--

import os

import pandas as pd

import matplotlib.pyplot  as plt

import numpy as np

import matplotlib.dates as mdates

df1=pd.read_excel("PAN Country.xls")

df1.plot(x='Date',y='Inflation',title="countryinflation",marker='.',markersize=6,lw=1, color="Red",label='Inflation',legend=True,figsize=(15,7),grid=True,linestyle=':',alpha=1,stacked=True)

plt.ylabel('Inflation (%)',fontsize=15)

plt.xlabel('Plot duration',fontsize=15)

plt.ylim(0, 0.35)

plt.gca().xaxis.set_major_locator(mdates.DayLocator(8))

plt.show()

如何在此数据上创建线性趋势线。请帮助我是新手

标签: python

解决方案


推荐阅读