Die beste Art und Weise, die ich gefunden ist durch diese einfache Sache zu tun:
from rpy2.robjects.packages import importr
from rpy2.robjects import pandas2ri
import rpy2.robjects as robjects
dataframe = robjects.r('data.frame')
df_rpy2 = dataframe([1,2,],[5,6])
df_pd = pd.DataFrame({'A': [1,2], 'B': [5,6]})
base = importr('base') #Creates an instance of R's base package
pandas2ri.activate() #Converts any pandas dataframe to R equivalent
base.colnames(df_pd) #Finds the column names of the dataframe df_pd
base.colnames(df_rpy2) #Finds the column names of the dataframe df_rpy2
Die Ausgabe lautet:
R object with classes: ('character',) mapped to:
<StrVector - Python:0x7fa3504d3048/R:0x10f65ac0>
['X1L', 'X2L', 'X5L', 'X6L']
R object with classes: ('character',) mapped to:
<StrVector - Python:0x7fa352493548/R:0x103b6e40>
['A', 'B']
Dies sowohl für den Datenrahmen arbeitet Pandas & rpy2 erstellt. Hoffe das hilft!