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

    1. <tfoot id='1ZWi6'></tfoot>

      <small id='1ZWi6'></small><noframes id='1ZWi6'>

          <bdo id='1ZWi6'></bdo><ul id='1ZWi6'></ul>
        <legend id='1ZWi6'><style id='1ZWi6'><dir id='1ZWi6'><q id='1ZWi6'></q></dir></style></legend>

        如何在 Pandas 中转换 datetime 列的时区?

        时间:2023-09-14
            • <bdo id='97Bhv'></bdo><ul id='97Bhv'></ul>

                <small id='97Bhv'></small><noframes id='97Bhv'>

                <legend id='97Bhv'><style id='97Bhv'><dir id='97Bhv'><q id='97Bhv'></q></dir></style></legend>
                  <tbody id='97Bhv'></tbody>

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

                1. 本文介绍了如何在 Pandas 中转换 datetime 列的时区?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我有一列(非索引列),其中包含日期时间.例如,前五个条目如下所示:

                  I have a column (non-index column) that has datetimes inside it. For example, the first five entries look something like this:

                  [Timestamp('2018-11-15 19:57:55'),
                   Timestamp('2018-11-15 19:59:46'),
                   Timestamp('2018-11-15 20:00:59'),
                   Timestamp('2018-11-15 20:01:41'),
                   Timestamp('2018-11-15 20:01:54')]
                  

                  我想将条目从 UTC 转换为太平洋时区.假设该列被称为 times 我目前正在执行以下操作:

                  I want to convert the entries from UTC to the Pacific timezone. Assuming the column is called times I am currently doing the following:

                  times.dt.tz_localize('GMT').dt.tz_convert('America/Los_Angeles')

                  虽然这成功地将列从 UTC 转换为 PST,但输出包含我不想要的无关组件.如下所示:

                  While this successfully converts the column from UTC to PST, the output has extraneous components that I do not want. It looks like the following:

                  [Timestamp('2018-11-15 11:57:55-0800', tz='America/Los_Angeles'),
                   Timestamp('2018-11-15 11:59:46-0800', tz='America/Los_Angeles'),
                   Timestamp('2018-11-15 12:00:59-0800', tz='America/Los_Angeles'),
                   Timestamp('2018-11-15 12:01:41-0800', tz='America/Los_Angeles'),
                   Timestamp('2018-11-15 12:01:54-0800', tz='America/Los_Angeles')]
                  

                  如何从时间戳中删除或忽略 -0800?谢谢!

                  How do I remove or ignore the -0800 from the timestamps? Thanks!

                  推荐答案

                  只需添加最后一步.tz_localize(None):

                  import pandas as pd
                  d = pd.Series(['2018-11-15 19:57:55', '2018-11-15 19:59:46'])
                  d = pd.to_datetime(d)
                  d
                  0   2018-11-15 19:57:55
                  1   2018-11-15 19:59:46
                  dtype: datetime64[ns]
                  
                  d_pacific_tz_aware = d.dt.tz_localize("GMT").dt.tz_convert('America/Los_Angeles')
                  d_pacific_tz_aware
                  0   2018-11-15 11:57:55-08:00
                  1   2018-11-15 11:59:46-08:00
                  dtype: datetime64[ns, America/Los_Angeles]
                  
                  
                  d_pacific_tz_naive = d.dt.tz_localize("GMT").dt.tz_convert('America/Los_Angeles').dt.tz_localize(None)
                  d_pacific_tz_naive
                  0   2018-11-15 11:57:55
                  1   2018-11-15 11:59:46
                  dtype: datetime64[ns]
                  

                  这篇关于如何在 Pandas 中转换 datetime 列的时区?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:如何将明天(在特定时间)日期转换为时间戳 下一篇:对于 1970-01-01 之前的日期,Windows 上 datetime time

                  相关文章

                  最新文章

                  <tfoot id='US35P'></tfoot>

                      <bdo id='US35P'></bdo><ul id='US35P'></ul>
                  1. <small id='US35P'></small><noframes id='US35P'>

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