参考链接:
https://stackoverflow.com/questions/64106628/why-assertionerror-having-numpy-ndarray
df.index = pd.to_datetime(df.index)
df = df.sort_index()
df_sub = df['2018'] # select the whole year of 2018
df_sub2 = df['2018-02'] # select the given month
df_sub3 = df['2018-01':'2018-03'] # select between dates