python - AttributeError:“DataFrame”对象没有属性“dtype”
问题描述
我认识了
py_get_attr_impl(x,name,silent)中的错误:AttributeError:'DataFrame'对象没有属性'dtype'
在 R 中使用 reticulate 包在 R 中调用 python 代码。
python中的代码运行正常。我不确定这个错误来自哪里。我正在使用 pvlib python 库在构建数据库中调用一些。
我的代码是 R 是:
library('reticulate')
pd <- import('pandas')
pvlib <- import('pvlib')
np <- import('numpy')
sandia_modules = pvlib$pvsystem$retrieve_sam('SandiaMod')
cec_inverters = pvlib$pvsystem$retrieve_sam("CECInverter")
cec_inverters = pvlib$pvsystem$retrieve_sam("CECInverter")
当我在 python 中运行代码时遇到问题,但在 R 中运行相同的命令却给了我错误。我不确定问题是什么。请帮我解决这个问题。
python中类似的代码是:
import pandas as pd
import numpy as np
import pvlib
sandia_modules = pvlib.pvsystem.retrieve_sam('SandiaMod')
cec_inverters = pvlib.pvsystem.retrieve_sam('cecinverter')
我试图寻找解决方案,但到目前为止没有发现任何有用的东西。
这是回溯:
10: stop(list(message = "AttributeError: 'DataFrame' object has no attribute 'dtype'",
call = py_get_attr_impl(x, name, silent), cppstack = list(
file = "", line = -1L, stack = "C++ stack not available on this system")))
9: .Call(`_reticulate_py_get_attr_impl`, x, name, silent)
8: py_get_attr_impl(x, name, silent)
7: py_get_attr(x, name)
6: `$.python.builtin.object`(x[[column]], "dtype")
5: x[[column]]$dtype
4: py_to_r(x[[column]]$dtype$name)
3: py_to_r.pandas.core.frame.DataFrame(result)
2: py_to_r(result)
1: pvlib$pvsystem$retrieve_sam("CECInverter")
解决方案
尝试使用中的as
参数import()
。您的代码也对我出错,但这有效:
library(reticulate) # version 1.6
pd <- import('pandas', as = "pd")
pvlib <- import('pvlib', as = "pvlib")
np <- import('numpy', as = "np")
sandia_modules <- pvlib$pvsystem$retrieve_sam('SandiaMod')
cec_inverters <- pvlib$pvsystem$retrieve_sam("CECInverter")
推荐阅读
- r - 在R中的文本字段中提取句点之前的数字
- vba - 如何使用 vba 宏按钮在 power point 幻灯片放映期间添加和调整形状?
- kubernetes - 删除“preview”和“jx-staging”环境下分别通过“jx preview”和“jx promote”部署的服务的k8s资源
- reactjs - 使用 useDispatch Hook 时出现问题 - 警告:React 检测到 Hook 的顺序发生了变化
- c++ - 在 CMAKE target_include_libraries 中理解“接口”的问题
- android - Flutter:Json解析
- c# - 如何在特定时区向 DateTime 添加一天
- javascript - 如何通过调用函数来更改输入类型文件的值?
- python - 为什么 CNN 有时会犯高度自信的错误,如何解决这个问题?
- json - 使用 Newtonsoft 使用与解决方案无关的方法对 Json 进行序列化/反序列化