0

enter image description here

I just updated conda and Rstudio and now dataframes will not show up correctly in RStudio. R dataframes show up correctly but not pandas (image attached). The pandas dataframes are correctly displayed in the console. I have updated all pandas and all of my RStudio packages.

2 Answers 2

0

Solution 1: Convert to an R data.frame

The simplest solution could be to explicitly convert the pandas DataFrame to an R data.frame using py_to_r(). This way, R will display it using its native formatting:

library(reticulate)
pd <- import("pandas")
df <- pd$DataFrame(data = list(a = 1:5, b = letters[1:5]))
r_df <- py_to_r(df)
print(r_df)

This converts the pandas DataFrame into an R data.frame, which will be displayed in the standard R format.

Solution 2: Render the HTML representation

If you prefer to maintain the HTML formatting provided by pandas (for instance, in an R Markdown document or in RStudio’s Viewer), you can use the DataFrame’s to_html() method and then render the HTML:

library(reticulate)
library(htmltools)
pd <- import("pandas")
df <- pd$DataFrame(data = list(a = 1:5, b = letters[1:5]))
HTML(df$to_html())

This will display the table with enhanced formatting in environments that support HTML.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for the response. However, this does not work. In the R format, it also keeps the weird array like rows. I've used reticulate for years and have always been able to just normally view dataframes so something is weird with the update and versions of packages I have. I am wondering if what builds View() in RStudio needs upgrades or if RStudio has settings to change this.
0

I needed to update R, not just RStudio!

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.