【问题标题】:python pandas iloc works on jupyter but not on flaskpython pandas iloc 适用于 jupyter 但不适用于烧瓶
【发布时间】:2018-11-19 16:49:37
【问题描述】:

我正在从flask 开发一个API,为此我不得不在函数之间使用pandas。因此,为了访问数据,我使用了 pandas iloc,但它显示错误“IndexError: single positional indexer is out-of-bounds”。

这是我的代码:

price = float(cf.loc[cf['company_name'] == 'Agricultural Development Bank Limited', 'Close'].iloc[0])
return price

如果我在 jupyter 上运行同样的东西,那么它会完美运行。

Cjeck out the screenshot of running this code in jupyter notebook

请帮忙。

【问题讨论】:

    标签: python pandas flask


    【解决方案1】:

    它可能试图索引一个空的数据框。为了说明,请尝试运行:

    df = pd.DataFrame()
    df.iloc[0]
    

    【讨论】:

      猜你喜欢
      • 2020-06-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-02-01
      相关资源
      最近更新 更多