The below code creates a scatter plot in python using pandas plotting functions
import pandas as pd
data = {'col1': [1,2,3,4,5],
'col2': [6,7,8,9,10]}
df = pd.DataFrame(data)
df.plot.scatter(x='col1', y='col2', alpha=0.3)
I am trying to recreate the plot function using reticulate. So far I have gotten to:
library(reticulate)
pd <- reticulate::import('pandas')
df <- data.frame(col1=c(1,2,3,4,5), col2=c(6,7,8,9,19))
#how do I recreate the python code for
#df.plot.scatter(x='col1', y='col2', alpha=0.3) using reticulate?
I know I could do this easily using ggplot2 but the objective is to use the pandas function within an r script (not rmarkdown script) using reticulate.
Any suggestions?
You need to use
r_to_pyfunction to get the dataframe in the python environment and from there you access it using python code with ther.prefix.