How to convert a panda series to a time series?

Refresh

December 2018

Views

1.1k time

2

I am trying to extract data from MYSQL server and making a dataframe out of it.The SQL query I use is

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')

This is working perfectly fine but when I use the function df=obtain_df(ticker) (obtain_df is just the function to get the dataframe) and use type(df['High']) it panda.series and not as timeseries? I don't know the reason for this. In my SQL server also date is in the format 'DATE'.

Can you suggest how I convert the series to timeseries ?

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

da.set_index('Date')

print da.head()

I get the following outputenter image description here

How do i make the date column as index.

1 answers

0

Пытаться:

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

или же:

 df['Date'] = pd.to_datetime(df['Date'])

Если у вас есть datetimeв необычном формате:

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