【问题标题】:Int64Index object has no attribute get_valuesInt64Index 对象没有属性 get_values
【发布时间】:2022-01-25 17:42:23
【问题描述】:

我正在做以下手册:https://towardsdatascience.com/mapping-geograph-data-in-python-610a963d2d7f

我从这段代码中收到以下错误:

# Plot Comuna
comuna = 'SANTIAGO'
com_id = df[df.NOM_COMUNA == comuna].index.get_values()[0]
plot_shape(com_id, comuna)

错误

AttributeError: 'Int64Index' 对象没有属性 'get_values'

【问题讨论】:

  • 只是df['tableName'].values df['tableName'].index 获取所有索引,而不是给定索引的值

标签: python pandas jupyter-notebook data-science


【解决方案1】:

使用 to_numpy() because get_values is deprecated 从 pandas 版本 0.25.0 开始。

试试:

comuna = 'SANTIAGO'
com_id = df[df.NOM_COMUNA == comuna].index.to_numpy()[0]
plot_shape(com_id, comuna)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-07-05
    • 2019-09-08
    • 1970-01-01
    • 1970-01-01
    • 2012-12-01
    • 2021-08-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多