1. <legend id='z2HL5'><style id='z2HL5'><dir id='z2HL5'><q id='z2HL5'></q></dir></style></legend>

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

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

        在 pandas to_datetime 中使用时区

        using time zone in pandas to_datetime(在 pandas to_datetime 中使用时区)
      1. <tfoot id='Lf1u4'></tfoot>

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

              • <bdo id='Lf1u4'></bdo><ul id='Lf1u4'></ul>

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

                    <tbody id='Lf1u4'></tbody>

                • 本文介绍了在 pandas to_datetime 中使用时区的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有时间从 epochs 时间戳我使用 data.Time_req = pd.to_datetime(data.Time_req)但是我得到了 UTC 时间,我需要从给定时间开始 +5:30.我如何告诉熊猫使用 'IST' 时区或只是 5hrs 30 mins 进一步使用它当前显示的时间.例如.7 hrs 应该变成 12:30 hrs 等等.

                  I have time from epochs timestamps I use data.Time_req = pd.to_datetime(data.Time_req) But I get UTC time, I need +5:30 from the given time. How do I tell pandas to use 'IST' timezone or just 5hrs 30 mins further to the time it currently shows me. eg. 7 hrs should become 12:30 hrs and so on.

                  推荐答案

                  可以使用tz_localize 将时区设置为 UTC/+0000,然后 tz_convert 添加你想要的时区:

                  You can use tz_localize to set the timezone to UTC/+0000, and then tz_convert to add the timezone you want:

                  start = pd.to_datetime('2015-02-24')
                  rng = pd.date_range(start, periods=10)
                  
                  df = pd.DataFrame({'Date': rng, 'a': range(10)})  
                  
                  df.Date = df.Date.dt.tz_localize('UTC').dt.tz_convert('Asia/Kolkata')
                  print (df)
                                         Date  a
                  0 2015-02-24 05:30:00+05:30  0
                  1 2015-02-25 05:30:00+05:30  1
                  2 2015-02-26 05:30:00+05:30  2
                  3 2015-02-27 05:30:00+05:30  3
                  4 2015-02-28 05:30:00+05:30  4
                  5 2015-03-01 05:30:00+05:30  5
                  6 2015-03-02 05:30:00+05:30  6
                  7 2015-03-03 05:30:00+05:30  7
                  8 2015-03-04 05:30:00+05:30  8
                  9 2015-03-05 05:30:00+05:30  9
                  

                  使用时区.

                  如果需要只添加Timedelta:

                  df.Date = df.Date + pd.Timedelta('05:30:00')
                  print (df)
                                   Date  a
                  0 2015-02-24 05:30:00  0
                  1 2015-02-25 05:30:00  1
                  2 2015-02-26 05:30:00  2
                  3 2015-02-27 05:30:00  3
                  4 2015-02-28 05:30:00  4
                  5 2015-03-01 05:30:00  5
                  6 2015-03-02 05:30:00  6
                  7 2015-03-03 05:30:00  7
                  8 2015-03-04 05:30:00  8
                  9 2015-03-05 05:30:00  9
                  

                  注意:添加 Timedelta 将更改与 datetime 对象关联的纪元时间戳.对于许多应用程序来说,这可能不是所希望的.

                  NOTE: Adding Timedelta will change the epoch timestamp associated with the datetime object. This may not be desired for many applications.

                  这篇关于在 pandas to_datetime 中使用时区的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Is there a good dependency analysis tool for Python?(Python有没有好的依赖分析工具?)
                  pandas dataframe to mariadb database with to_sql and sqlalchemy(使用 to_sql 和 sqlalchemy 到 mariadb 数据库的 pandas 数据框)
                  Rotation of 3D vector?(3D矢量的旋转?)
                  OpenCV Python rotate image by X degrees around specific point(OpenCV Python围绕特定点将图像旋转X度)
                  Tkinter Listbox(Tkinter 列表框)
                  How to avoid tkinter lt;lt;ListboxSelectgt;gt; and .curselection() detecting events/selection outside of Listbox?(如何避免 tkinter lt;lt;ListboxSelectgt;gt;和 .curselection() 检测列表框之外的事件/选择?)

                          <tbody id='3U33b'></tbody>
                        • <bdo id='3U33b'></bdo><ul id='3U33b'></ul>
                          <legend id='3U33b'><style id='3U33b'><dir id='3U33b'><q id='3U33b'></q></dir></style></legend>
                          <i id='3U33b'><tr id='3U33b'><dt id='3U33b'><q id='3U33b'><span id='3U33b'><b id='3U33b'><form id='3U33b'><ins id='3U33b'></ins><ul id='3U33b'></ul><sub id='3U33b'></sub></form><legend id='3U33b'></legend><bdo id='3U33b'><pre id='3U33b'><center id='3U33b'></center></pre></bdo></b><th id='3U33b'></th></span></q></dt></tr></i><div id='3U33b'><tfoot id='3U33b'></tfoot><dl id='3U33b'><fieldset id='3U33b'></fieldset></dl></div>

                          <small id='3U33b'></small><noframes id='3U33b'>

                          <tfoot id='3U33b'></tfoot>