Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/66.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_Mysql_Pandas - Fatal编程技术网

Python 如何将熊猫系列转换为时间系列?

Python 如何将熊猫系列转换为时间系列?,python,mysql,pandas,Python,Mysql,Pandas,我试图从MYSQL服务器中提取数据,并从中生成一个数据框架 sql="""SELECT dp.Date, dp.Open , dp.High, dp.Low, dp.Close, dp.Volume, dp.Adj FROM tickers AS tick INNER JOIN daily_price AS dp ON dp.ticker_id = tick.id WHERE tick.ticker = '%s' ORDER BY dp.Dat

我试图从MYSQL服务器中提取数据,并从中生成一个数据框架

sql="""SELECT dp.Date, dp.Open , dp.High, dp.Low, dp.Close, dp.Volume, dp.Adj 
     FROM tickers AS tick
     INNER JOIN daily_price AS dp
     ON dp.ticker_id = tick.id
     WHERE tick.ticker = '%s'
     ORDER BY dp.Date ASC;"""%(ticker)
goog = psql.frame_query(sql, con=con, index_col='Date')
这工作得非常好,但是当我使用函数
df=get_-df(ticker)
get_-df
只是获取
数据帧的函数)并使用
类型(df['High'])
panda.series
,而不是
timeseries
?我不知道这是为什么。在我的SQL server中,日期的格式也是“日期”

你能建议我如何把这个系列转换成timeseries吗

da['Date']=pd.DatetimeIndex(da['Date'])

da.set_index('Date')

print da.head()
我得到以下输出

如何将日期列作为索引。

尝试:

 df['Date'] = pd.DatetimeIndex(df['Date'])
或:

如果您有异常格式的
datetime

 df['Date'] = pd.to_datetime(df['Date'], format="%d%m%Y")

举一些来自
dataframe
的数据为例。您的数据目前是什么格式的?你可以用df['Date']来测试这一点。dtype
df['Date']。dtype将其作为一个对象,因此如何更改数据帧的日期数据是从yahoo OHLCV数据下载的股票。它说series对象没有。to_datetime属性我使用了第一个属性,它确实起作用,但知道它无法将我的日期设置为索引,有关更多信息,请查看问题
da.set_index(da['Date'])中的我的编辑。
 df['Date'] = pd.to_datetime(df['Date'], format="%d%m%Y")