DataFrame时间索引

在低版本的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']就不会出现报错

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值