It suggested to me on stack overflow to open an issue about it.
The constructor for DataFrame in rpy2 doesn't expose the parameter
available for the R function data.frame.
The trick suggested by lgautier is to do the following in Python:
from rpy2.robjects import pandas2ri from rpy2.robjects.packages import importr base = importr('base') pandas2ri.activate() ... # CONVERT PANDAS DF TO R DF rdf = pandas2ri.py2ri(pydf) # FIND COLUMN INDEX OF EACH FACTOR IN DF factors = [i for i,col in enumerate(rdf) if col.rclass == 'factor'] # CONVERT COLS ITERATIVELY for f in factors: rdf[f] = base.as_character(rdf[f])
or I found that the following is working in R:
i <- sapply(df, is.factor) df[i] <- lapply(df[i], as.character)
It will be nice instead to pass the argument
to the converter.
Thanks a lot Cheers Fabien