如何绘制趋势线作为日期的函数?

2024-05-15 14:20:22 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图在与我的实际数据值相同的图上绘制一条取决于日期(格式为2018年9月14日至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) 

最后,我收到一个打字错误,基本上说它无法将9月14日…12月18日的日期转换为数字。所以我想我的问题可以归结为:如何将日期格式转换成数字?我找到的所有例子都是整洁的isoformat


Tags: ofthetodatasize格式figloc