Skip to content

Pandas DataFrame not converting to R data.frame #1875

@garciamikep

Description

@garciamikep

Issue

Pandas DataFrame is not converting to native R data.frame, either automatically or via reticulate::r_to_py()

Steps:

  • use a Python venv specified via reticulate::use_virtualenv()
  • load pandas via reticulate::import()
  • create a Pandas df from scratch
    • not auto-converted
  • run reticulate::r_to_py() on pandas DataFrame
    • still not converted to R data.frame

Reprex

reticulate::use_virtualenv("path/to/.venv/with/pandas")

pd <- import("pandas", convert=TRUE)

# create pandas df
pd_df <- pd$DataFrame(list(a=c(1,2,3), b=c(4,5,6)))
class(pd_df) # pandas.DataFrame

# attempt to convert to R df 
r_df <- pd_df |> reticulate::r_to_py()
class(r_df) # still pandas.DataFrame

# unsurprisingly, returns pandas methods, not R data.frame columns
# I need to be able to work with r_df as an R data.frame
names(r_df$a)

reticulate::py_config()

Note: This venv has Pandas v2.3.1 installed.

python:         /Users/mike.garcia/Desktop/pd-reticulate/.venv/bin/python
libpython:      /Users/mike.garcia/.pyenv/versions/3.11.9/lib/libpython3.11.dylib
pythonhome:     /Users/mike.garcia/Desktop/pd-reticulate/.venv:/Users/mike.garcia/Desktop/pd-reticulate/.venv
version:        3.11.9 (main, Sep  4 2024, 09:25:45) [Clang 15.0.0 (clang-1500.3.9.4)]
numpy:          /Users/mike.garcia/Desktop/pd-reticulate/.venv/lib/python3.11/site-packages/numpy
numpy_version:  2.4.1
pandas:         /Users/mike.garcia/Desktop/pd-reticulate/.venv/lib/python3.11/site-packages/pandas

NOTE: Python version was forced by use_python() function

sessionInfo()

R version 4.5.2 (2025-10-31)
Platform: aarch64-apple-darwin20
Running under: macOS Tahoe 26.2

Matrix products: default
BLAS:   /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib 
LAPACK: /Library/Frameworks/R.framework/Versions/4.5-arm64/Resources/lib/libRlapack.dylib;  LAPACK version 3.12.1

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

time zone: America/Los_Angeles
tzcode source: internal

attached base packages:
[1] stats     graphics  grDevices datasets  utils     methods   base     

other attached packages:
[1] reticulate_1.44.1   data.table_1.18.2.1 devtools_2.4.6     
[4] usethis_3.2.1      

loaded via a namespace (and not attached):
 [1] R6_2.6.1          fastmap_1.2.0     Matrix_1.7-4      lattice_0.22-7   
 [5] magrittr_2.0.4    remotes_2.5.0     cachem_1.1.0      glue_1.8.0       
 [9] memoise_2.0.1     png_0.1-8         lifecycle_1.0.5   cli_3.6.5        
[13] sessioninfo_1.2.3 grid_4.5.2        vctrs_0.7.1       renv_0.15.0      
[17] compiler_4.5.2    pkgload_1.4.1     purrr_1.2.1       tools_4.5.2      
[21] pkgbuild_1.4.8    ellipsis_0.3.2    Rcpp_1.1.1        jsonlite_2.0.0   
[25] rlang_1.1.7       fs_1.6.6     

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions