In [1]:
import numpy as np
import pandas as pd
In [2]:
df = pd.DataFrame({"y": [1, 2, 3]},
                  index=pd.to_datetime(["2019-03-31 00:00:00",
                                        "2019-05-31 00:00:00",
                                        "2019-08-31 00:00:00"]))
In [3]:
df.index.to_period("M")
Out[3]:
PeriodIndex(['2019-03', '2019-05', '2019-08'], dtype='period[M]', freq='M')

Infer the daily frequency

In [4]:
idx = pd.date_range("2019-01-01", periods=2)
idx.to_period()
Out[4]:
PeriodIndex(['2019-01-01', '2019-01-02'], dtype='period[D]', freq='D')