Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/326.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/date/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何绘制趋势线作为日期的函数?_Python_Date_Trendline_Best Fit - Fatal编程技术网

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

Python 如何绘制趋势线作为日期的函数?,python,date,trendline,best-fit,Python,Date,Trendline,Best Fit,我试图在与我的实际数据值相同的图上绘制一条取决于日期(格式为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 a

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

尝试使用
pd.to\u datetime()

import pandas as pd

dates = pd.to_datetime(dh1018['BILLDATE'])