【问题标题】:Index(...) must be called with a collection of some kind, 'electric bus 0' was passed必须使用某种集合调用索引(...),传递了“电动巴士 0”
【发布时间】:2020-12-02 04:48:42
【问题描述】:

我正在使用这个名为 PyPSA(用于能源系统分析的 Python)的软件。

我正在编写一个小代码来创建用于电力传输的总线。但是,当我使用这个名为.madd() 的特殊函数输入多个值时。 (Network.madd(class_name, names, suffix='', **kwargs)。我得到一个错误。我是python程序的初学者。

n = pypsa.Network()

for i in range(3):
    n.madd("Bus","electric bus {}".format(i),v_nom=20, x=x_value, y=y_value)
print(n.buses)
TypeError: Index(...) must be called with a collection of some kind, 'electric bus 0' was passed

【问题讨论】:

    标签: python pandas indexing group-by


    【解决方案1】:

    我不知道 PyPSA 但是根据 documentation 作为 names (第二个参数) 你应该提供一个列表或 pandas.Index 对象

    我假设您应该将此 for 循环移动到参数本身并在那里创建一个列表。像这样:

    n.madd("Bus",[F"electric bus {x}" for x in range(3)], v_nom=20, x=x_value, y=y_value)
    

    不确定 F 表示法是否适用于您的 python 版本,因此您也可以这样做

    n.madd("Bus",["electric bus {}".format(x) for x in range(3)], v_nom=20, x=x_value, y=y_value)
    

    【讨论】:

    • 如果答案正确,您可以将答案标记为正确
    猜你喜欢
    • 2022-06-15
    • 2016-11-30
    • 2021-05-31
    • 2022-10-18
    • 1970-01-01
    • 2015-09-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多