Movatterモバイル変換


[0]ホーム

URL:


Skip to main content
Ctrl+K

pandas.DataFrame.tz_convert#

DataFrame.tz_convert(tz,axis=0,level=None,copy=None)[source]#

Convert tz-aware axis to target time zone.

Parameters:
tzstr or tzinfo object or None

Target time zone. PassingNone will convert toUTC and remove the timezone information.

axis{0 or ‘index’, 1 or ‘columns’}, default 0

The axis to convert

levelint, str, default None

If axis is a MultiIndex, convert a specific level. Otherwisemust be None.

copybool, default True

Also make a copy of the underlying data.

Note

Thecopy keyword will change behavior in pandas 3.0.Copy-on-Writewill be enabled by default, which means that all methods with acopy keyword will use a lazy copy mechanism to defer the copy andignore thecopy keyword. Thecopy keyword will be removed in afuture version of pandas.

You can already get the future behavior and improvements throughenabling copy on writepd.options.mode.copy_on_write=True

Returns:
Series/DataFrame

Object with time zone converted axis.

Raises:
TypeError

If the axis is tz-naive.

Examples

Change to another time zone:

>>>s=pd.Series(...[1],...index=pd.DatetimeIndex(['2018-09-15 01:30:00+02:00']),...)>>>s.tz_convert('Asia/Shanghai')2018-09-15 07:30:00+08:00    1dtype: int64

Pass None to convert to UTC and get a tz-naive index:

>>>s=pd.Series([1],...index=pd.DatetimeIndex(['2018-09-15 01:30:00+02:00']))>>>s.tz_convert(None)2018-09-14 23:30:00    1dtype: int64

[8]ページ先頭

©2009-2025 Movatter.jp