我正在尝试在与我的实际数据值相同的图上绘制取决于日期(以 2018 年 9 月 14 日至 2018 年 12 月的形式)的趋势线。
我试过使用 Seaborn:
#dh1018['BILLDATE'] returns a pandas series of strings containing the dates from Sep-14 to Dec-2018.
dh1018=df.loc[107:158,['BILLDATE','Covel']]
dates=dh1018['BILLDATE']
#plotting the actual data
plot(dates, dh1018['Covel'], label='Covel')
#trying to get that trend line
import seaborn as sns
sns.regplot(x=dates, y=dh1018['Covel'], data=dh1018, fit_reg=True)
xlabel('Billdate')
ylabel('Monthly kWh')
title('Monthly kWh of Dining Hall Buildings 2010-2018')
legend(loc='best')
fig_size=rcParams["figure.figsize"]
fig_size[0]=20
fig_size[1]=10
_=plt.xticks(rotation=90)
最后,我收到一个 TypeError 基本上说它无法将日期 Sep-14...Dec-18 转换为数字。所以我想我的问题归结为:如何将日期格式转换为数字?我发现的所有示例都采用整洁的等格式。