Inability to convert pandas data timestamp

I am new to Pandas and trying to understand why this timestamp will not convert. For example, one individual timestamp is the string '2010-10-06 16:38:02' . The code is as follows:

 newdata = pd.DataFrame.from_records(data, columns = ["col1", "col2", "col3", "timestamp"], index = "timestamp") newdata.index = newdata.index.tz_localize('UTC').tz_convert('US/Eastern') 

And gets this error:

 AttributeError: 'Index' object has no attribute 'tz_localize' 

Someone commented here that tz_localize is not a method available for index types, so I tried converting it as a column instead, but that gave an error

 TypeError: index is not a valid DatetimeIndex or PeriodIndex 

And then I found this site , which says that tz_localize only affects the index.

If anyone can help me, it will be very grateful! I am using Pandas 0.15.2. I believe this code may have worked for someone else with an earlier version, but I cannot switch.

EDIT:

Well, after a little busting, I found that it does not cause any errors and seems to do what I want in the short term: newdata.index=pd.DatetimeIndex(newdata.index).tz_localize('UTC').tz_convert('US/β€Œβ€‹Eastern')

+7
python timezone pandas timestamp indexing
source share
2 answers

I was asked to add an official answer instead of just editing my question, so here it is. Please note that it builds the answer above, but that this does not work for me.

newdata.index=pd.DatetimeIndex(newdata.index).tz_localize('UTC').tz_convert('US/β€Œβ€‹Eastern')

+1
source share

You first need to convert the index column to series type in pandas:

 newdata.index.to_series().tz_localize('UTC').tz_convert('US/Eastern') 
0
source share

All Articles