• <small id='1Kr5f'></small><noframes id='1Kr5f'>

    <tfoot id='1Kr5f'></tfoot>
  • <legend id='1Kr5f'><style id='1Kr5f'><dir id='1Kr5f'><q id='1Kr5f'></q></dir></style></legend>
      <bdo id='1Kr5f'></bdo><ul id='1Kr5f'></ul>

      1. <i id='1Kr5f'><tr id='1Kr5f'><dt id='1Kr5f'><q id='1Kr5f'><span id='1Kr5f'><b id='1Kr5f'><form id='1Kr5f'><ins id='1Kr5f'></ins><ul id='1Kr5f'></ul><sub id='1Kr5f'></sub></form><legend id='1Kr5f'></legend><bdo id='1Kr5f'><pre id='1Kr5f'><center id='1Kr5f'></center></pre></bdo></b><th id='1Kr5f'></th></span></q></dt></tr></i><div id='1Kr5f'><tfoot id='1Kr5f'></tfoot><dl id='1Kr5f'><fieldset id='1Kr5f'></fieldset></dl></div>

      2. python pandas TimeStamps到夏令时的本地时间字符串

        时间:2023-09-14

        <small id='xCWT5'></small><noframes id='xCWT5'>

            <tbody id='xCWT5'></tbody>

            • <bdo id='xCWT5'></bdo><ul id='xCWT5'></ul>
              1. <tfoot id='xCWT5'></tfoot>

                <legend id='xCWT5'><style id='xCWT5'><dir id='xCWT5'><q id='xCWT5'></q></dir></style></legend>
                <i id='xCWT5'><tr id='xCWT5'><dt id='xCWT5'><q id='xCWT5'><span id='xCWT5'><b id='xCWT5'><form id='xCWT5'><ins id='xCWT5'></ins><ul id='xCWT5'></ul><sub id='xCWT5'></sub></form><legend id='xCWT5'></legend><bdo id='xCWT5'><pre id='xCWT5'><center id='xCWT5'></center></pre></bdo></b><th id='xCWT5'></th></span></q></dt></tr></i><div id='xCWT5'><tfoot id='xCWT5'></tfoot><dl id='xCWT5'><fieldset id='xCWT5'></fieldset></dl></div>
                  本文介绍了python pandas TimeStamps到夏令时的本地时间字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我有一个带有 TimeStamps 列的数据框.我想将其转换为本地时间字符串,即夏令时.

                  I have a dataframe with a TimeStamps column. I want to convert it to strings of local time, ie with daylight saving.

                  所以我想将下面的 ts[0] 转换为2015-03-30 03:55:05".Pandas 似乎知道 DST,但仅当您在系列上调用 .values 时.

                  So I want to convert ts[0] below to "2015-03-30 03:55:05". Pandas seems to be aware of DST, but only when you call .values on the series.

                  谢谢

                  (Pdb) ts = df['TimeStamps']
                  (Pdb) ts
                  0   2015-03-30 02:55:05.993000
                  1   2015-03-30 03:10:20.937000
                  2   2015-03-30 10:09:19.947000
                  Name: TimeStamps, dtype: datetime64[ns]
                  (Pdb) ts[0]
                  Timestamp('2015-03-30 02:55:05.993000')
                  (Pdb) ts.values
                  array(['2015-03-30T03:55:05.993000000+0100',
                     '2015-03-30T04:10:20.937000000+0100',
                     '2015-03-30T11:09:19.947000000+0100'], dtype='datetime64[ns]')
                  

                  推荐答案

                  DST 与您所在的位置相关(例如,伦敦 DST 比纽约晚几周开始).您首先需要知道时间戳时区:

                  DST is relative to your location (e.g. London DST began a few weeks after NY). You first need to make the timestamp timezone aware:

                  from pytz import UTC
                  from pytz import timezone
                  import datetime as dt
                  
                  ts = pd.Timestamp(datetime.datetime(2015, 3, 31, 15, 47, 25, 901597))
                  # or...
                  ts = pd.Timestamp('2015-03-31 15:47:25.901597')
                  # ts is a Timestamp, but it has no idea where in the world it is...
                  >>> ts.tzinfo is None
                  True
                  
                  # So the timestamp needs to be localized.  Assuming it was originally a UTC timestamp, it can be localized to UTC.
                  ts_utc = ts.tz_localize(UTC)
                  # Once localized, it can be expressed in other timezone regions, e.g.: 
                  eastern = pytz.timezone('US/Eastern')
                  ts_eastern = ts_utc.astimezone(eastern)
                  # And to convert it to an ISO string of local time (e.g. eastern):
                  >>> ts_eastern.isoformat()
                  '2015-03-30T08:09:27.143173-04:00'
                  

                  参见 pytz 或 日期时间了解更多信息.

                  See pytz or datetime for more information.

                  这篇关于python pandas TimeStamps到夏令时的本地时间字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:在 pandas.Series 中将时间戳转换为 datetime.datetime 下一篇:什么-&gt;在 Python 函数定义中是什么意思?

                  相关文章

                  最新文章

                  <small id='POu0r'></small><noframes id='POu0r'>

                1. <i id='POu0r'><tr id='POu0r'><dt id='POu0r'><q id='POu0r'><span id='POu0r'><b id='POu0r'><form id='POu0r'><ins id='POu0r'></ins><ul id='POu0r'></ul><sub id='POu0r'></sub></form><legend id='POu0r'></legend><bdo id='POu0r'><pre id='POu0r'><center id='POu0r'></center></pre></bdo></b><th id='POu0r'></th></span></q></dt></tr></i><div id='POu0r'><tfoot id='POu0r'></tfoot><dl id='POu0r'><fieldset id='POu0r'></fieldset></dl></div>

                2. <legend id='POu0r'><style id='POu0r'><dir id='POu0r'><q id='POu0r'></q></dir></style></legend>

                    <tfoot id='POu0r'></tfoot>
                      <bdo id='POu0r'></bdo><ul id='POu0r'></ul>