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

Weighted average for every possible range [closed]
Pandas multi index dataframe to nested dictionarry
No module named zipline (Python 64 bit and Windows 64 bit)
Mapping to similar times in Pandas
Pandas Unmelt dataset
multicollinearity for one-hot encoding
How to work with 'NA' in pandas?
Pandas DataFrame.assign arguments
zipline error KeyError: <type 'zipline.assets._assets.Equity'>
How can i split 'Date' column into 'Date' and 'Time' column? [closed]
Pandas customized group aggregation
What is the significance of t-stats value while applying ttest_ind on two pandas series?
Align order of multiindex dataframe with the order of another multiindex df, pandas
From Object To Date in Pandas [duplicate]
How do I configure PyCharm to Pandas
cannot convert nan to int (but there are no nans)

Categories

HOME
google-chrome-extension
magnific-popup
layout
iot
mean-stack
rsyslog
sqlite3
gps
win32gui
umd
angular-ui-bootstrap
onelogin
basic
applepay
facebook-php-sdk
gnupg
reveal.js
zend-framework3
circuit
django-simple-history
django-cms
firefox-webextensions
java-3d
clickonce
icloud-api
emgucv
qhull
cas
semantic-analysis
django-storage
facebook-access-token
internet-explorer-9
fopen
srcset
unboundid
typed.js
avcapturesession
hexo
catalog
io-redirection
scaffold
service-discovery
ensembles
powershell-dsc
nand2tetris
arena-simulation
heightmap
gpx
long-polling
taffy
pebble-watch
imanage
django-scheduler
quartz-composer
spring-android
rotativa
sts-springsourcetoolsuite
database-optimization
google-web-starter-kit
markojs
ubuntu-10.04
dlna
hexdump
design-by-contract
asp.net5
sdhc
jqgrid-formatter
dukescript
fluid-dynamics
sortedlist
nstableviewcell
applescript-objc
socketexception
websocket4net
balanced-payments
mbr
viadeo
uv-mapping
xsockets.net
batterylevel
orchardcms-1.7
pygit2
html-editor
angularjs-controller
typoscript2
armcc
errai
dbproviderfactories
enter
postgresql-performance
amazon-appstore
javax.script
calling-convention
datareader
radcombobox
site.master
gallio
wise
icanhaz.js
dbal
substrings
javap
spec#

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