【问题标题】:'RangeIndex' object is not callable\'RangeIndex\' 对象不可调用
【发布时间】:2022-10-06 15:11:21
【问题描述】:

应用重复变量创建时找不到索引。 我不确定如何用 2 个数据框过滤它。

代码

index_100 = globals()[\'df_n{}\'.format(i)][\'value\'].index(100)

错误

\'RangeIndex\' object is not callable

    标签: python dataframe


    【解决方案1】:

    如果要查找索引中的第 101 个元素,则需要使用 [] 进行索引

    index_100 = globals()['df_n{}'.format(i)]['value'].index[100]
    

    【讨论】:

    • index_100 = globals()['df_n{}'.format(i)]['value'].index[globals()['df_n{}'.format(i)]==100] 感谢您的回复。我还有其他问题。我得到一个错误“数组的索引太多:数组是一维的,但有2个被索引”,但原始数据是[11485行x 1列]所以似乎没有问题。我可以知道原因吗?
    • @yunahwang globals()['df_n{}'.format(i)]==100 返回一个布尔数据帧,而数据帧是二维 numpy 数组。您不能将其用作索引。如果您的原始问题得到解决,您可以单击接受按钮。
    • 谢谢你的答案。那么当值为 100 时如何获取索引呢?
    • @yunahwang 添加专栏。
    • 哦,问题解决了,感谢您的帮助,我正在编辑它,如下所示index_100 = globals()['df_n{}'.format(i)]['value'].index[globals()['df_n{}'.format(i)]['value']==100] --> Int64Index([11317, 11318, 11319, 11320, 11321, 11322, 11323, 11324, 11325, 11326, ... 11475, 11476, 11477、11478、11479、11480、11481、11482、11483、11484]
    猜你喜欢
    • 2019-08-21
    • 1970-01-01
    • 2021-08-21
    • 2018-09-30
    • 2021-02-18
    • 1970-01-01
    • 2016-10-01
    • 2015-01-29
    • 2014-03-17
    相关资源
    最近更新 更多