18

I created a dataframe. Running some commands on the iPython I get the following results:

In [5]: df.tail()
Out[5]: 
                 open     high      low    close  volume
date                                                        
2017-02-22 15:00  1.05131  1.05137  1.05074  1.05075     543
2017-02-22 15:30  1.05074  1.05165  1.05072  1.05139     506
2017-02-22 16:00  1.05137  1.05193  1.05121  1.05141     488
2017-02-22 16:30  1.05144  1.05205  1.05056  1.05065     747
2017-02-22 17:00  1.05061  1.05167  1.04988  1.04997     753

In [6]: df.index[0]
Out[6]: '2011-11-21 14:30'

In [7]: type(df.index[0])
Out[7]: str

As you see, the index is in str format but I need it to be in Timestamp format. Is it possible?

1 Answer 1

22

Try this

df.index = pd.to_datetime(df.index)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.