python - 在 Pandas 中获取 KeyError
问题描述
我正在尝试从不同的模块调用一个函数,如下所示:
module1 - func1: returns a dataframe
module1 - func2(p_df_in_fromfunc1)
功能2:
for i in range(0,len(p_df_in_fromfunc1):
# Trying to retrieve row values of individual columns and assign to variables
v_tmp = p_df_in_fromfunc1.loc[i,"Col1"]
尝试运行上述代码时,出现错误:
关键错误 0
问题可能是因为我没有零编号的行吗?
解决方案
在不了解您的代码的情况下,我的猜测是,对于位置索引,如果您对索引方式感兴趣,请尝试使用 iloc 而不是 loc。就像是:
v_tmp = p_df_in_fromfunc1.iloc[i,"Col1"]
推荐阅读
- javascript - 从输入中自动减去金额
- algorithm - Incremental price graph approximation
- haskell - Couldn't match expected type ‘[Char]’ with actual type ‘Int’
- curl - 如何进行 curl 发布请求并仅获取状态码作为响应?
- r - R Shiny Dashboard,更改所有超链接的颜色
- html - 滚动容器中的粘页脚取决于内容的高度
- oracle - dbms_datapump.get_dumpfile_info 在存储过程中编译时无法读取目录
- rspec - 为什么我不能在 to_raise 匹配器中捕获 Capybara::ElementNotFound ?
- python - Google Cloud Text To Speech 中的权限错误 - Python
- frontend - Apollo 客户端缓存在没有参数的嵌套对象上使用 cacheRedirects 重定向