search
Search
Login
Map of Data Science
menu
menu search toc more_vert
Robocat
Guest 0reps
Sign up
Log in
account_circleMy Profile homeAbout paidPricing
emailContact us
exit_to_appLog out
Map of data science
Thanks for the thanks!
close
Comments
Log in or sign up
Cancel
Post
account_circle
Profile
exit_to_app
Sign out
help Ask a question
Share on Twitter
search
keyboard_voice
close
Searching Tips
Search for a recipe:
"Creating a table in MySQL"
Search for an API documentation: "@append"
Search for code: "!dataframe"
Apply a tag filter: "#python"
Useful Shortcuts
/ to open search panel
Esc to close search panel
to navigate between search results
d to clear all current filters
Enter to expand content preview
icon_star
Doc Search
icon_star
Code Search Beta
SORRY NOTHING FOUND!
mic
Start speaking...
Voice search is only supported in Safari and Chrome.
Navigate to
A
A
brightness_medium
share
arrow_backShare
Twitter
Facebook

Pandas DataFrame | tz_convert method

Pandas
chevron_right
Documentation
chevron_right
DataFrame
chevron_right
Time Series
schedule Jul 1, 2022
Last updated
local_offer PythonPandas
Tags
map
Check out the interactive map of data science

Pandas DataFrame.tz_convert(~) method converts the timezone of the row or column index.

Parameters

1. tzlink | string or tzinfo object

The timezone to convert into.

2. axis | int or string | optional

Whether to convert row labels or column labels:

Axis

Description

Row labels are converted

0 or "index"

Column labels are converted

1 or "columns"

By default, axis=0.

3. level | int or string | optional

The level to target. This is only relevant if the source DataFrame is multi-index. By default, level=None.

4. copy | boolean | optional

  • If True, then a new DataFrame is returned. Modifying this DataFrame will not mutate the source DataFrame, and vice versa.

  • If False, then no new DataFrame is created - modifying the returned DataFrame will mutate the source DataFrame, and vice versa.

By default, copy=True.

Return Value

A DataFrame with the date-index's timezone converted.

Examples

Basic usage

Consider the following DataFrame:

index_date = pd.date_range("2020-12-25", "2020-12-26", tz="Asia/Tokyo")
df = pd.DataFrame({"A":[4,5]}, index=index_date)
df
A
2020-12-25 00:00:00+09:00 4
2020-12-26 00:00:00+09:00 5

Here, the index is of type datetime64, and the timezone is set to Asia/Tokyo.

To convert the timezone into Europe/Paris:

result = df.tz_convert(tz="Europe/Paris") # axis=0
result
A
2020-12-24 16:00:00+01:00 4
2020-12-25 16:00:00+01:00 5

Converting column labels

Consider the following DataFrame:

df = pd.DataFrame({pd.Timestamp("2020-12-25", tz="Asia/Tokyo"):[4,5]})
df
2020-12-25 00:00:00+09:00
0 4
1 5

Here, the column label is of type datetime64, and the timezone is set in Asia/Tokyo.

To convert the timezone into Europe/Paris:

df.tz_convert(tz="Europe/Paris", axis=1)
2020-12-24 16:00:00+01:00
0 4
1 5
robocat
Published by Isshin Inada
Edited by 0 others
Did you find this page useful?
thumb_up
thumb_down
Ask a question or leave a feedback...
thumb_up
0
thumb_down
0
chat_bubble_outline
0
settings
Enjoy our search
Hit / to insta-search docs and recipes!