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')
python timezone pandas timestamp indexing
Erin
source share