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

Pandas resampling hourly timeseries into hourly proportion timeseries
How to customize headers and column widths of DataFrame display?
horizontally centered xlabels for pandas timeseries plotting
drop a single tuple from a multi tuple column
Accessing Row from Previous Day in Pandas Dataframe with Apply
Select a multiple-key cross section from a DataFrame
“Reindexing only valid with uniquely valued Index objects”
How can I divide single values of a dataframe by monthly averages?
How to generate pandas DataFrame column of Categorical from string column?
How to perform key-restricted broadcast-operate-update in Pandas?
partial update to dataframe with Multi-index index with integer labels
IPython Notebook: What is the default encoding?
Append new columns to HDFStore with pandas
Pandas: reindex multiindex, broadcast results
TypeError when changing an integer data series in pandas
Pandas file IO Read Error

Categories

HOME
sendgrid
pdf
deployment
listview
mediawiki
deezer
ngrx
dictionary
plot
session
dot
cplex
kalman-filter
google-docs
jsrender
jgroups
qore
elasticsearch-hadoop
metatrader4
phaser
ups
designer
ghc
jsdoc
angular-ui
connection-string
normalizr
shared-hosting
jasonette
tokenize
facebook-instant-articles
chromium-embedded
core-text
devops
claims-based-identity
lcd
firebase-crash-reporting
apache-commons-io
delicious-api
bcd
uisplitview
oracle-fusion-middleware
textmate
language-concepts
mmenu
mpmediaquery
environment-modules
picasso
bootstrapper
unoconv
email-templates
dynamic-reports
gpx
websphere-mq-fte
powercli
veracode
tizen-native-app
togetherjs
darcs
slickedit
typed-lambda-calculus
pdfclown
jspdf-autotable
spring-mongodb
dynamics-sl
yt-project
mikroc
packagist
whois
ios4
msys
composite
angular-local-storage
tt-news
asp.net-web-api-odata
onactivityresult
responsive-slides
reactfx
picturefill
didselectrowatindexpath
centos5
intentservice
cdc
eventual-consistency
sharp-repository
html-editor
selected
browser-detection
errai
deobfuscation
yui-datatable
mysql-error-1005
floating
.nettiers
dbal
webkit.net
zend-tool
libs
geneva-server





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