<tfoot id='DlGSp'></tfoot>
  • <small id='DlGSp'></small><noframes id='DlGSp'>

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

      <legend id='DlGSp'><style id='DlGSp'><dir id='DlGSp'><q id='DlGSp'></q></dir></style></legend>
        • <bdo id='DlGSp'></bdo><ul id='DlGSp'></ul>

        在 pandas.Series 中将时间戳转换为 datetime.datetime

        时间:2023-09-14
      1. <i id='w32dX'><tr id='w32dX'><dt id='w32dX'><q id='w32dX'><span id='w32dX'><b id='w32dX'><form id='w32dX'><ins id='w32dX'></ins><ul id='w32dX'></ul><sub id='w32dX'></sub></form><legend id='w32dX'></legend><bdo id='w32dX'><pre id='w32dX'><center id='w32dX'></center></pre></bdo></b><th id='w32dX'></th></span></q></dt></tr></i><div id='w32dX'><tfoot id='w32dX'></tfoot><dl id='w32dX'><fieldset id='w32dX'></fieldset></dl></div>
        <legend id='w32dX'><style id='w32dX'><dir id='w32dX'><q id='w32dX'></q></dir></style></legend>

          <bdo id='w32dX'></bdo><ul id='w32dX'></ul>

            <tbody id='w32dX'></tbody>

          1. <small id='w32dX'></small><noframes id='w32dX'>

                  <tfoot id='w32dX'></tfoot>
                1. 本文介绍了在 pandas.Series 中将时间戳转换为 datetime.datetime的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我有熊猫系列,其中索引是整数列表(时间戳),我如何将它们转换为 datetime.datetime(带时区)比以下原始转换更有效?

                  I have pandas Series where index is a list of integer (timestamp), how can I convert them to datetime.datetime (with timezone) more efficient than below raw conversion?

                  pd.Series(data=s.values, index=map(lambda x:datetime.datetime.fromtimestamp(x,tz=utc), s.index))
                  

                  推荐答案

                  In [49]: s = Series(range(10))
                  

                  使用to_datetime,你可以提供一个单位来选择整数的含义.

                  Using to_datetime, you can supply a unit to select what the meaning of the integers.

                  In [50]: pd.to_datetime(s,unit='s')
                  Out[50]: 
                  0   1970-01-01 00:00:00
                  1   1970-01-01 00:00:01
                  2   1970-01-01 00:00:02
                  3   1970-01-01 00:00:03
                  4   1970-01-01 00:00:04
                  5   1970-01-01 00:00:05
                  6   1970-01-01 00:00:06
                  7   1970-01-01 00:00:07
                  8   1970-01-01 00:00:08
                  9   1970-01-01 00:00:09
                  dtype: datetime64[ns]
                  
                  In [51]: pd.to_datetime(s,unit='ms')
                  Out[51]: 
                  0          1970-01-01 00:00:00
                  1   1970-01-01 00:00:00.001000
                  2   1970-01-01 00:00:00.002000
                  3   1970-01-01 00:00:00.003000
                  4   1970-01-01 00:00:00.004000
                  5   1970-01-01 00:00:00.005000
                  6   1970-01-01 00:00:00.006000
                  7   1970-01-01 00:00:00.007000
                  8   1970-01-01 00:00:00.008000
                  9   1970-01-01 00:00:00.009000
                  dtype: datetime64[ns]
                  
                  In [52]: pd.to_datetime(s,unit='D')
                  Out[52]: 
                  0   1970-01-01
                  1   1970-01-02
                  2   1970-01-03
                  3   1970-01-04
                  4   1970-01-05
                  5   1970-01-06
                  6   1970-01-07
                  7   1970-01-08
                  8   1970-01-09
                  9   1970-01-10
                  dtype: datetime64[ns]
                  

                  创建一个系列就很简单了

                  Creating a Series is then straightforward

                  In [54]: Series(s.values,index=pd.to_datetime(s,unit='s'))
                  Out[54]: 
                  1970-01-01 00:00:00    0
                  1970-01-01 00:00:01    1
                  1970-01-01 00:00:02    2
                  1970-01-01 00:00:03    3
                  1970-01-01 00:00:04    4
                  1970-01-01 00:00:05    5
                  1970-01-01 00:00:06    6
                  1970-01-01 00:00:07    7
                  1970-01-01 00:00:08    8
                  1970-01-01 00:00:09    9
                  dtype: int64
                  

                  这篇关于在 pandas.Series 中将时间戳转换为 datetime.datetime的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:Python 按日期列出分组 下一篇:python pandas TimeStamps到夏令时的本地时间字符串

                  相关文章

                  最新文章

                  <tfoot id='mAnyg'></tfoot>
                    <legend id='mAnyg'><style id='mAnyg'><dir id='mAnyg'><q id='mAnyg'></q></dir></style></legend>
                      <bdo id='mAnyg'></bdo><ul id='mAnyg'></ul>

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

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