I am trying to set different timezones for various rows in a Pandas dataframe based on a criterion. As a MWE, here is what I have tried:
test = pd.DataFrame( data = pd.to_datetime(['2015-03-30 20:12:32','2015-03-12 00:11:11']) ,columns=['time'] )
test['new_col']=['new','old']
test.time=test.set_index('time').index.tz_localize('UTC')
test.loc[test.new_col=='new','time']=test[test.new_col=='new'].set_index('time').index.tz_convert('US/Pacific')
print test
The output of this:
time new_col
0 1427746352000000000 new
1 2015-03-12 00:11:11+00:00 old
As you can see, the row with the updated timezone is converted to an integer. How can I do this properly so that the updated entry is a datetime?