asdflkjwqerqwr
asdflkjwqerqwr

Reputation: 1189

Pandas: how to convert an index of int64 years to datetime

I have an int64 index representing year values that I want to treat as a timestamp index:

df.index
Int64Index([2001,2002,2003], dtype='int64')

How do I convert the index to a datetime timestamp in pandas?

Upvotes: 15

Views: 18299

Answers (1)

Alex
Alex

Reputation: 19104

import pandas as pd
df.index = pd.to_datetime(df.index, format='%Y')

Upvotes: 32

Related Questions