Hi all, I am working to automate a routine workflow I do in ArcGIS Pro, specifically reading in a csv, geocoding, filling in some additional fields, and appending to hosted feature service in AGOL.
I am having trouble with the very first step - reading in a local csv using pandas and I think it's a file path problem. I have tried in both ArcGIS Pro and Online Notebooks thinking Pro would handle the file path better. I tried os.cwd() in AGOL and it says /arcgis, so I can't tell if it's a directory problem.
I know sometimes Python has trouble reading certain slashes or file path format, but I have tried the following combinations and they are all saying No such file or directory
df = pd.read_csv(r"C:\Users\Documents\GeocodeFile.csv")
df = pd.read_csv("C:\\Users\\Documents\\GeocodeFile.csv")
csv_file = 'C:/Users/Documents/GeocodeFile.csv' (this one just keeps the string, trying to import any data still doesn't work).
I am trying to avoid having to upload the csv as an item to AGOL and access it that way because I want to have this process be as automated as possible. There must be an easier way to do this! Am I missing anything?
Good Morning,
Have you tried placing the file in a different path (e.g. C:\temp) to see if it can read from there? This way you can at least confirm that reading a file from a local path either works or doesn't.
Also, for the path you've indicated.....should there be a UserName in there somewhere? (e.g. C:\Users\[your user name]\Documents\GeocodeFile.csv)?
Mark
Just thought of something else. If the notebook you are creating is via your Enterprise Portal....then the issue is an access issue. For example. When I am in my Enterprise Portal and I select Notebook and create a new notebook, when I run the os.getcwd() it comes back as c:\\arcgis. That's because the notebook is technically running from the Notebook Server. So unless you have your csv file saved directly to the Documents folder on the Notebook Server machine then you won't be able to access it. You will need to have a shared folder created in your local environment and then give access to that folder to the Notebook Server (whatever is the name of the OS user/group that is actually running the Notebook server). For my environment, we have a specific windows AD account that was created to run all the Notebook server tasks. This AD user would then be given permission to access the shared folder on a network or local drive this way any files that are in that shared folder could be called from the notebook via that shared folder path (e.g. \\machine_name\shared_folder_name\your_csv_file.csv
Mark
As suggested above, you might want to double-check the path to your CSV file - normally your username will be between \Users\ and \Documents. Either of the first two options you list should work fine, though.
You can test it w/ the following code that generates then reads a CSV from your C:\Temp directory:
import pandas as pd
# First let's make some small example data as a test
data = {
"x": [45.2, 54.1, 33.2],
"y": [-120.34, -121.3, -122.1]
}
# Load it to a Data Frame
test_df = pd.DataFrame(data)
# Save that to a CSV
test_df.to_csv('c:\\Temp\\test_file.csv')
# Can we read that back as a CSV?
df = pd.read_csv('c:\\Temp\\test_file.csv')
df.head()
Dealing with the Notebook file workspace on AGOL is a whole different kettle of fish - it has some unique behaviors that can make it tricky to move code between AGOL and ArcGIS Pro.