Working with Pandas dataframe in RStudio IDE

Hi all,
Sorry for the super first timer newb question here, but I am looking to run python code within a RNotebook (in RStudio IDE), specifically within a python code chunk. My newb question is about the output of a dataframe from the code chunk. When I print a Pandas dataframe it does not show all the columns like when a dataframe is "rendered" from a R code chunk. Is there a better way to view a Pandas dataframe from a Python code chunk within RStudio IDE? Ultimately I would like to have the ability to look at the columns and rows of a Pandas dataframe similarly to how you can with a dataframe from the R code chunk. I am aware of the way to view the data from within the Environment tab, just wondering about from within a Python code chunk.

Source data used
Source data location

Code used to import and display a Pandas dataframe

import pandas as pd

apt_reg_py = pd.read_csv("data/Apartment Building Registration Data.csv")
print(apt_reg_py)

Output Pandas dataframe using print()

        _id  ... NO_BARRIERFREE_ACCESSBLE_UNITS
0     86632  ...                            NaN
1     86633  ...                            NaN
2     86634  ...                            NaN
3     86635  ...                            NaN
4     86636  ...                            NaN
...     ...  ...                            ...
3478  90110  ...                            NaN
3479  90111  ...                            NaN
3480  90112  ...                            NaN
3481  90113  ...                            NaN
3482  90114  ...                            NaN

[3483 rows x 70 columns]

Hi there, I know you mentioned you want to pretty-up the output within the python chunk itself, but how about leveraging the reticulate package to pass the python object back into R so you can view it using like you would an R tibble or data frame? For instance, after your python chunk, you would have an R chunk with something like:

# Read python object into R using 'py$` syntax
apt_reg_r = as_tibble(py$apt_reg_py)

# View R object as per usual
glimpse(apt_reg_r)
print(apt_reg_r)

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.