在低版本的pandas中可以使用frame[string] df['2018-01'] 直接搜索某一时间片段的表格数据,
但在pandas1.2.3版本中出现了:
FutureWarning: Indexing a DataFrame with a datetimelike index using a single string to slice the rows, like `frame[string]`, is deprecated and will be removed in a future version. Use `frame.loc[string]` instead.
在DataFrame的时间索引中极不赞成使用单独的字符来对特定行进行选取,并将会在未来的版本中对这种方法移除,推荐使用.loc的方式对行进行选取
例如在pandas2.0.3中使用df['2018']出现
raise KeyError(key) from err
KeyError: '2018'
因此DataFrame数据利用时间序列索引时最好写成df.loc['2018']
可能是以此来区分与列索引的不同
通过列索引提取一列以后,再直接利用df['2018']就不会出现报错