search
Search
Login
Unlock 100+ guides
menu
menu
web
search toc
close
Comments
Log in or sign up
Cancel
Post
account_circle
Profile
exit_to_app
Sign out
What does this mean?
Why is this true?
Give me some examples!
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

Pandas DataFrame | tz_convert method

schedule Aug 10, 2023
Last updated
local_offer
PythonPandas
Tags
mode_heat
Master the mathematics behind data science with 100+ top-tier guides
Start your free 7-days trial now!

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

0 or "index"

Row labels are converted

1 or "columns"

Column labels are converted

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
Comment
Citation
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!