Issue
This Content is from Stack Overflow. Question asked by ankit
I have to run both python and R code in azure ml notebook but since this is not working for me. So, I have made a import_dataframe.py
file as:
import pandas
import subprocess
import sys
def read_df():
subprocess.check_call([sys.executable, "-m", "pip", "install", azureml-core])
from azureml.core import Dataset, Datastore
from azureml.core import Workspace, Dataset
subscription_id = 'abc'
resource_group = 'pqr'
workspace_name = 'xyz'
workspace = Workspace(subscription_id, resource_group, workspace_name)
datastore = Datastore.get(workspace, 'workspaceblobstore')
# create tabular dataset from all parquet files in the directory
tabular_dataset_3 = Dataset.Tabular.from_parquet_files(path=(datastore,'/UI/09-17-2022_125003_UTC/userdata1.parquet'))
df=tabular_dataset_3.to_pandas_dataframe()
return df
Now in the notebook with R
kernel, I am using the following lines of code:
library(reticulate)
source_python("import_dataframe.py")
df <- read_df()
But I am getting the following error:
Error in py_call_impl(callable, dots$args, dots$keywords): NameError: name 'azureml' is not defined
Traceback:
1. read_df()
2. py_call_impl(callable, dots$args, dots$keywords)
Can anyone please help me to resolve this error ? Any help would be appreciated.
Solution
I replicate your situation on my system and it works.
You can use this set of library versions:
R version: 4.2.1
rpy2 version: 3.4.5
Pandas version: 1.3.5
This Question was asked in StackOverflow by ankit and Answered by Shishu Kumar Choudhary It is licensed under the terms of CC BY-SA 2.5. - CC BY-SA 3.0. - CC BY-SA 4.0.