ModuleNotFoundError: No module named ‘pandas.rpy‘

Posted Data+Science+Insight

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ModuleNotFoundError: No module named ‘pandas.rpy‘相关的知识,希望对你有一定的参考价值。

ModuleNotFoundError: No module named 'pandas.rpy'

pandas升级后原来的pandas.rpy全部整合到了rpy2中;

问题:

import pandas.rpy.common as pdcom

r_data = pdcom.convert_to_r_dataframe(self.data)

import pandas as pd
import pandas.rpy.common as pdcom
import rpy2.robjects as ro
from test import resources_dir, root_test_dir, r_results_dir, load_default_data, load_r_results
from os import path


#data setup and validation
r_data = pdcom.convert_to_r_dataframe(self.data)
r_predictors = self.predictors if isinstance(self.predictors, str) \\
else ro.vectors.StrVector(self.predictors)
#ensure all variables are properly set and make special r values for
#use in calling the r function

解决:

from rpy2.robjects import pandas2ri
pandas2ri.activate()

from rpy2.robjects import pandas2ri
pandas2ri.activate()

import pandas as pd
import numpy as np
from datetime import datetime
n = 10
df = pd.DataFrame({
    "timestamp": [datetime.now() for t in range(n)],
    "value": np.random.uniform(-1, 1, n)
})
r_dataframe = pandas2ri.py2ri(df)
print(r_dataframe)

完整错误:

Traceback (most recent call last):
  File "r_analysis.py", line 12, in <module>
    import pandas.rpy.common as pdcom
ModuleNotFoundError: No module named 'pandas.rpy'

参考:Converting a Pandas DataFrame to R dataframe using Rpy2
参考:https://www.coder.work/article/1256019
参考:https://stackoverflow.com/questions/45221609/

以上是关于ModuleNotFoundError: No module named ‘pandas.rpy‘的主要内容,如果未能解决你的问题,请参考以下文章

ModuleNotFoundError: No module named 'gdbm'

Python:ModuleNotFoundError: No module named 'windows'

PySpark 自定义 UDF ModuleNotFoundError: No module named

用Java调用.py程序出现ModuleNotFoundError: No module named 'java'

ModuleNotFoundError: No module named 'jupyter_contrib_nbextensions' .ipynb文件转换.py文件时遇到错误(示例

ModuleNotFoundError: No module named 'jupyter_contrib_nbextensions' .ipynb文件转换.py文件时遇到错误(示例