pandasのdatetimeの丸めの基準はどこか

# 忙しい人のための回答

1970年1月1日0時0分0秒 っぽい

# はじめに

pandas では roundやfloorを用いで日付を丸めることが出来ます．
それは1分や1時間のような単位だけでなく，5分毎に丸める，といった操作も可能です．
5分ごとにまとめる場合は，例えば次のようにします．

```python:sample1.py

import pandas as pd

dates = pd.date_range('1/1/2021 00:00:00', periods=10, freq='min')
print("original date:")
print(dates)
print("floor date:")
print(dates.floor('5T'))
```

```sh:実行結果

original date:
DatetimeIndex(['2021-01-01 00:00:00', '2021-01-01 00:01:00',
               '2021-01-01 00:02:00', '2021-01-01 00:03:00',
               '2021-01-01 00:04:00', '2021-01-01 00:05:00',
               '2021-01-01 00:06:00', '2021-01-01 00:07:00',
               '2021-01-01 00:08:00', '2021-01-01 00:09:00'],
              dtype='datetime64[ns]', freq='T')

floor date:
DatetimeIndex(['2021-01-01 00:00:00', '2021-01-01 00:00:00',
               '2021-01-01 00:00:00', '2021-01-01 00:00:00',
               '2021-01-01 00:00:00', '2021-01-01 00:05:00',
               '2021-01-01 00:05:00', '2021-01-01 00:05:00',
               '2021-01-01 00:05:00', '2021-01-01 00:05:00'],
              dtype='datetime64[ns]', freq=None)
```

ここで気になるのが，5分のようにキリの良い数字ではなく，7分のようなキリの悪い数字を使った際の挙動です．

# 検証

例えば[pandas.Series.dt.floorのreference](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.Series.dt.floor.html)を読んでも

> Perform floor operation on the data to the specified freq.

としか書いてなかったので，実際にやってみます．
2021年年始と1970年年始で挙動を確認してみます．

```python:sample2.py

import pandas as pd

dates = pd.date_range('1/1/2021 00:00:00', periods=14, freq='min')
print("original date:")
print(dates)
print("floor date:")
print(dates.floor('7T'))

dates = pd.date_range('1/1/1970 00:00:00', periods=14, freq='min')
print("original date:")
print(dates)
print("floor date:")
print(dates.floor('7T'))
```

```sh:実行結果
original date:
DatetimeIndex(['2021-01-01 00:00:00', '2021-01-01 00:01:00',
               '2021-01-01 00:02:00', '2021-01-01 00:03:00',
               '2021-01-01 00:04:00', '2021-01-01 00:05:00',
               '2021-01-01 00:06:00', '2021-01-01 00:07:00',
               '2021-01-01 00:08:00', '2021-01-01 00:09:00',
               '2021-01-01 00:10:00', '2021-01-01 00:11:00',
               '2021-01-01 00:12:00', '2021-01-01 00:13:00'],
              dtype='datetime64[ns]', freq='T')

floor date:
DatetimeIndex(['2020-12-31 23:55:00', '2020-12-31 23:55:00',
               '2021-01-01 00:02:00', '2021-01-01 00:02:00',
               '2021-01-01 00:02:00', '2021-01-01 00:02:00',
               '2021-01-01 00:02:00', '2021-01-01 00:02:00',
               '2021-01-01 00:02:00', '2021-01-01 00:09:00',
               '2021-01-01 00:09:00', '2021-01-01 00:09:00',
               '2021-01-01 00:09:00', '2021-01-01 00:09:00'],
              dtype='datetime64[ns]', freq=None)

original date:
DatetimeIndex(['1970-01-01 00:00:00', '1970-01-01 00:01:00',
               '1970-01-01 00:02:00', '1970-01-01 00:03:00',
               '1970-01-01 00:04:00', '1970-01-01 00:05:00',
               '1970-01-01 00:06:00', '1970-01-01 00:07:00',
               '1970-01-01 00:08:00', '1970-01-01 00:09:00',
               '1970-01-01 00:10:00', '1970-01-01 00:11:00',
               '1970-01-01 00:12:00', '1970-01-01 00:13:00'],
              dtype='datetime64[ns]', freq='T')

floor date:
DatetimeIndex(['1970-01-01 00:00:00', '1970-01-01 00:00:00',
               '1970-01-01 00:00:00', '1970-01-01 00:00:00',
               '1970-01-01 00:00:00', '1970-01-01 00:00:00',
               '1970-01-01 00:00:00', '1970-01-01 00:07:00',
               '1970-01-01 00:07:00', '1970-01-01 00:07:00',
               '1970-01-01 00:07:00', '1970-01-01 00:07:00',
               '1970-01-01 00:07:00', '1970-01-01 00:07:00'],
              dtype='datetime64[ns]', freq=None)
```

やはりというべきか，（毎年の年始の0時0分のような基準ではなく）1970年1月1日0時0分基準のようですね．