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

Merge and sum Pandas Pivot Table
Counting null as percentage
appending list of lists to pd.Dataframe()
how to perform where and distinct count operation in pandas dataframe?
Pandas Dataframe - Using index as value when slicing/filtering
How can I select out columns where the first values are NaN?
Record limitation in pandas dataframe when importing from a csv file
count of unique values in pandas dataframe column
Rolling sums on pandas dataframe
Pandas Bug - Error when inserting list serialize as string
Formatting index of a pandas table in a plot
resample over consecutive chunks of large size CSV
Too many possibilities for categorical fields
How to install pandas on virtual machine?
How to change particular column value when defined mask is true?
Pandas/NumPy: concisely label first N values matching a mask

Categories

HOME
wso2-am
image
c#-4.0
tinymce
nullpointerexception
lodash
session
dot
getelementsbytagname
sqlite3
v8
mouse
session-variables
row
etl
static-libraries
decimal
designer
caml
serverless-framework
foselasticabundle
graphlab
database-replication
connection-string
ab-testing
contextmenu
textfield
ml
tar
ehcache
language-agnostic
zurb-foundation-6
cultureinfo
numerical-methods
dynamic-featured-image
nhapi
jspm
large-file-upload
vision
socialengine
google-cloud-endpoints-v2
contact-form
copying
normal-distribution
fusionpbx
file-format
restlet
swift3.0.2
libvpx
vapor
reportbuilder
azure-ml
graphenedb
mesos-chronos
hp-ux
quadratic-programming
gpx
long-polling
avconv
scrollable
hls.js
powercli
svmlight
brightcove
qtwebview
mako
flutterwave
color-profile
watchconnectivity
parallel-data-warehouse
httplistener
player
contact-list
disque
nsviewcontroller
persist
whois
fadeout
energy
browser-link
srand
browser-bugs
ionic
interrupted-exception
graph-drawing
system32
composite
oberon
angular-local-storage
jsapi
codeigniter-url
qcodo
nsbutton
mesa
aapt
dml
bundles
jboss-weld
android-2.2-froyo
didselectrowatindexpath
balanced-payments
flexmojos
tws
file-locking
simba
javaspaces
online-compilation
netbeans-6.9
jquery-ui-layout
removeclass
xtype
actionview
mongomapper
sortable-tables
modelstate
routedevent
asp.net-profiles
ti-dsp
swing-app-framework
privilege
post-build

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