代码之家  ›  专栏  ›  技术社区  ›  8-Bit Borges

Pandas-“str”和“int”实例之间不支持“>”

  •  0
  • 8-Bit Borges  · 技术社区  · 5 年前

    我想删除符合两个条件的所有行:

    df = df.drop(df[(df['home'] == 'away')
               &(df['ranking'] > 12)].index)
    

    但这是一个错误:

    TypeError: '>' not supported between instances of 'str' and 'int'
    

    我怎么解决这个问题?

    1 回复  |  直到 5 年前
        1
  •  1
  •   BENY    5 年前

    让我们试试

    df['ranking'] = pd.to_numeric(df['ranking'],errors='coerce')