pandas


localize timestamp in pandas


There are some questions about how to localiza a timestamp in pandas, but all of them require the column to be localized to be the index. I don't want that, I want to localize a column, which in not the index, for example:
df = pd.DataFrame({'start': pd.to_datetime([1439687730.439, 1439687731.439], unit='s')})
df['start'].tz_localize('utc')
this return me an error:
TypeError: index is not a valid DatetimeIndex or PeriodIndex
My goal is to convert the timestamp in my localtime (CEST) using pandas (datetime does it automatically).
You need to use .dt accessor as you're operating on a Series not a DatetimeIndex:
In [191]:
df = pd.DataFrame({'start': pd.to_datetime([1439687730.439, 1439687731.439], unit='s')})
df['start'].dt.tz_localize('utc')
Out[191]:
0 2015-08-16 01:15:30.439000+00:00
1 2015-08-16 01:15:31.439000+00:00
Name: start, dtype: datetime64[ns, UTC]
the tz_localize method is only available on datetimeIndex objects hence the error but it's available through the dt accessor

Related Links

How to add a column to all DataFrames inside a Panel (don't mind using a for loop)
What is the functionality of the filling method when reindexing?
Pandas, multiindex, dates, HDFstore and frame_tables
Binary operation broadcasting across multiindex
Insert or replace like operation for Pandas HDFStore (table)
Parsing excel files with Pandas
grouping by column and then doing a boxplot by the index in pandas
How to create a lagged data structure using pandas dataframe
pandas dataframe interpolate
pandas dataframe interpolating missing days
procedurally convert interval data to cross sectional data
Pandas Resample Strange Zero Tolerance Behavior
VLOOKUP equivalent function to look up value in pandas DataFrame
pandas dataframe shift dates
ipython dataframe plotting setting color parameter?
How to change string columns size for all columns in pandas hdfstore?

Categories

HOME
maven
twitter
bluetooth
image-processing
azure-data-factory
plot
layout
relay
kalman-filter
elm
jsrender
rdf
windows-server
enterprise-library-5
onelogin
ios-charts
append
contact
export-to-csv
jplayer
designer
oracle-coherence
jprofiler
xlsxwriter
clickonce
zurb-foundation-6
p-value
phpfox
tooltipster
linkerd
ejabberd-module
atlassian-crucible
webkitspeechrecognition
skia
binary-data
exuberant-ctags
caret
stringtemplate
xmlreader
bitbucket-pipelines
multilingual
event-driven
dynamics-crm-2013
withings
streamsets
streamreader
estimote
angular2-meteor
skeleton-css-boilerplate
rainbowtable
rdfs
nsarray
media-player
knpmenubundle
pdfclown
vtigercrm
migradoc
google-cdn
pintos
radtreelist
simplewebrtc
cloudbees
unity-networking
tcpserver
wso2cloud
angular-leaflet-directive
sailfish-os
census
web-controls
streambase
npapi
html-helper
has-many-through
heisenbug
pyhdf
jmapviewer
web2py-modules
dbconnection
ftps
shellexecute
dataadapter
padarn
jelly
robotics-studio
wsdl-2.0
free-variable
simba
chuck
runas
word-processor
dbproviderfactories
ocx
spyware
deobfuscation
tomcat-valve
datareader
html-input
gallio
substrings
nintendo-ds
microsoft-virtualization
backcolor
eqatec
simpletest
ugc
commodore
lzh

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App