how can I assign the dataframe data types to a variable in rpy2?

37 Views Asked by At

how can I assign the dataframe data types to a variable in rpy2?

The way I would do this in in Python is:

dt = df.dtypes
print(dt)

I have already tried the following in rpy2:

dt <- str(df)
print(dt)

but I get the following R Parsing error:

in R(self, line, cell, local_ns)

/usr/local/lib/python3.10/dist-packages/rpy2/rinterface_lib/_rinterface_capi.py in _parse(cdata, num, rmemory) 650 # PARSE_EOF 651 if status[0] != openrlib.rlib.PARSE_OK: --> 652 raise RParsingError('Parsing status not OK', 653 status=PARSING_STATUS(status[0])) 654 return res

RParsingError: Parsing status not OK - PARSING_STATUS.PARSE_ERROR

1

There are 1 best solutions below

0
Dan On

The parsing error was caused by the comment line at the beginning of the cell. rpy2 does not like the use of comments that begin and end with '''. '''