【问题标题】:select a column having particular year选择具有特定年份的列
【发布时间】:2019-09-14 08:04:12
【问题描述】:
year     Odisha
2011-12  2265
2012-13  112
2012-13  156
2014-15  172
2011-12  197

从数据框中选择 2012-13 年和 2014-15 年

year_df=new_df[(new_df['Duration']=='2013-14' & 
                new_df['Duration']=='2014-15')]

我得到了错误-:

无法将 dtyped [object] 数组与 [bool] 类型的标量进行比较

【问题讨论】:

    标签: pandas date dataframe


    【解决方案1】:

    您需要将& 更改为| 并添加)(

    year_df=new_df[(new_df['Duration']=='2013-14') | (new_df['Duration']=='2014-15')]
    

    使用Series.isin有什么相同之处:

    year_df=new_df[new_df['Duration'].isin(['2013-14', '2014-15'])]
    

    【讨论】:

      猜你喜欢
      • 2014-02-19
      • 1970-01-01
      • 2019-09-18
      • 1970-01-01
      • 2022-01-17
      • 2015-04-03
      • 1970-01-01
      • 2021-06-16
      • 1970-01-01
      相关资源
      最近更新 更多