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.
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.
Share Improve this question asked Mar 31 at 4:16 abby hudakabby hudak 233 bronze badges2 Answers
Reset to default 0Solution 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.
I needed to update R, not just RStudio!