为什么 pandas.DatetimeIndex 也被识别为 pd.Int64Index?
Why is a pandas.DatetimeIndex also identified as a pd.Int64Index?
即使下面显示的我的数据框的单级索引显然是 pd.DatetimeIndex,它仍然被识别为 pd.Int64Index。
接下来,我将通过 VS Code 调试控制台中的打印输出来演示此行为:
df.index
DatetimeIndex(['2018-01-01 00:00:00+01:00', '2018-01-01 01:00:00+01:00',
'2018-01-01 02:00:00+01:00', '2018-01-01 03:00:00+01:00',
'2018-01-01 04:00:00+01:00', '2018-01-01 05:00:00+01:00',
'2018-01-01 06:00:00+01:00', '2018-01-01 07:00:00+01:00',
'2018-01-01 08:00:00+01:00', '2018-01-01 09:00:00+01:00',
...
'2019-08-24 14:00:00+02:00', '2019-08-25 14:00:00+02:00',
'2019-08-26 14:00:00+02:00', '2019-08-26 15:00:00+02:00',
'2019-08-27 15:00:00+02:00', '2019-08-28 15:00:00+02:00',
'2019-08-29 14:00:00+02:00', '2019-08-30 14:00:00+02:00',
'2019-08-31 14:00:00+02:00', '2019-08-31 15:00:00+02:00'],
dtype='datetime64[ns, Europe/Madrid]', name='Time', length=13493, freq=None)
isinstance(df.index, pd.DatetimeIndex)
True
isinstance(df.index, pd.Int64Index)
True
使用的导入程序和模块版本注意事项:
我在 linux Lubuntu 18.04 LTS 上使用 Python 3.7.7(默认,2020 年 4 月 20 日,05:55:00)[GCC 5.4.0 20160609]。
至于pandas版本:1.0.5
来自source code:
> class DatetimeIndex(DatetimeTimedeltaMixin, DatetimeDelegateMixin):
> """
> Immutable ndarray of datetime64 data, represented internally as int64, and
> which can be boxed to Timestamp objects that are subclasses of datetime and
> carry metadata such as frequency information.
> [...]
即使下面显示的我的数据框的单级索引显然是 pd.DatetimeIndex,它仍然被识别为 pd.Int64Index。
接下来,我将通过 VS Code 调试控制台中的打印输出来演示此行为:
df.index
DatetimeIndex(['2018-01-01 00:00:00+01:00', '2018-01-01 01:00:00+01:00',
'2018-01-01 02:00:00+01:00', '2018-01-01 03:00:00+01:00',
'2018-01-01 04:00:00+01:00', '2018-01-01 05:00:00+01:00',
'2018-01-01 06:00:00+01:00', '2018-01-01 07:00:00+01:00',
'2018-01-01 08:00:00+01:00', '2018-01-01 09:00:00+01:00',
...
'2019-08-24 14:00:00+02:00', '2019-08-25 14:00:00+02:00',
'2019-08-26 14:00:00+02:00', '2019-08-26 15:00:00+02:00',
'2019-08-27 15:00:00+02:00', '2019-08-28 15:00:00+02:00',
'2019-08-29 14:00:00+02:00', '2019-08-30 14:00:00+02:00',
'2019-08-31 14:00:00+02:00', '2019-08-31 15:00:00+02:00'],
dtype='datetime64[ns, Europe/Madrid]', name='Time', length=13493, freq=None)
isinstance(df.index, pd.DatetimeIndex)
True
isinstance(df.index, pd.Int64Index)
True
使用的导入程序和模块版本注意事项:
我在 linux Lubuntu 18.04 LTS 上使用 Python 3.7.7(默认,2020 年 4 月 20 日,05:55:00)[GCC 5.4.0 20160609]。
至于pandas版本:1.0.5
来自source code:
> class DatetimeIndex(DatetimeTimedeltaMixin, DatetimeDelegateMixin):
> """
> Immutable ndarray of datetime64 data, represented internally as int64, and
> which can be boxed to Timestamp objects that are subclasses of datetime and
> carry metadata such as frequency information.
> [...]