Select to view content in your preferred language

Read local CSV file

268
4
Jump to solution
3 weeks ago
JaredPilbeam2
MVP Alum

This post was never resolved: https://community.esri.com/t5/arcgis-notebooks-questions/trouble-with-reading-local-csv-data-into-no...

I have the same question. I have a very simple script I'm attempting to use as a custom web tool in ExB. It works fine in Pro. In AGOL Notebooks I'm having trouble getting past the first function. It's probably because I'm not too familiar with Notebooks within AGOL. 

''' 
csv file > df > gdf > shp
'''
from arcgis.gis import GIS
gis = GIS("home")
import pandas as pd
import geopandas as gpd

# read csv file
f = r'C:\Users\me\Report_updated.csv'
file = pd.read_csv(f)

# convert to dataframe
df = pd.DataFrame(file)

# geocode
gdf = gpd.tools.geocode(df['ADDRESS'])

# extract lat long from geometry and put into dataframe
df['latitude'],df['longitude'],df['geometry'] = gdf.geometry.y, gdf.geometry.x, gdf.geometry

# generate GeometryArray of shapely Point geometries from x, y(, z) coordinates.
gdf = gpd.GeoDataFrame(df, geometry=gpd.points_from_xy(df.longitude, df.latitude), crs="EPSG:4326") #crs is optional

# write to shapefile
gdf.to_csv(r'C:\Users\me\report_geocode.csv')

 

I've put the file in local directories, network directories, used a relative path, reversed the slashes, etc... I usually end up with FileNotFoundError.

 

Tags (4)
0 Kudos
1 Solution

Accepted Solutions
Joshua-Young
MVP Regular Contributor

You have to put the CSV file somewhere that ArcGIS Online (AGO) Notebooks can access. It cannot access your local file system. I would recommend seeing this post https://community.esri.com/t5/arcgis-api-for-python-questions/writing-a-csv-from-python-notebook/td-... about the topic. I know they are talking about writing data but it discusses AGO Notebooks file access.

You could upload the CSV to the AGO Notebooks file system, publish it as an item on AGO, or host it on a online file share (provided you can authenticate to it in Notebooks).

"Not all those who wander are lost" ~ Tolkien

View solution in original post

0 Kudos
4 Replies
Joshua-Young
MVP Regular Contributor

You have to put the CSV file somewhere that ArcGIS Online (AGO) Notebooks can access. It cannot access your local file system. I would recommend seeing this post https://community.esri.com/t5/arcgis-api-for-python-questions/writing-a-csv-from-python-notebook/td-... about the topic. I know they are talking about writing data but it discusses AGO Notebooks file access.

You could upload the CSV to the AGO Notebooks file system, publish it as an item on AGO, or host it on a online file share (provided you can authenticate to it in Notebooks).

"Not all those who wander are lost" ~ Tolkien
0 Kudos
JaredPilbeam2
MVP Alum

Ok, thanks, useful info. It doesn't sound like this will work for what I'm trying to do. Ultimately, there will be non-GIS users uploading csv files in the ExB app from who knows what directories. 

0 Kudos
Joshua-Young
MVP Regular Contributor

@JaredPilbeam2 I found a more definitive answer for you in another post. As of June 2025, what you are trying to do is not possible with AGO Notebooks and custom web tools in Experience Builder. See the comment from @xlt208 on 06/03/2025.

https://community.esri.com/t5/arcgis-experience-builder-questions/how-to-allow-local-file-upload-wit... 

"Not all those who wander are lost" ~ Tolkien
JaredPilbeam2
MVP Alum

Thanks for that. I'm forced to find an alternative to the Add Data Tool in ExB. It has a BUG which stopped it from uploading a csv with a field labeled Address.

0 Kudos