I have a Python script in an ArcGIS Online Jupyter Notebook that processes GeoJSON data and saves a CSV file. It works perfectly when I run it cell-by-cell manually. However, when scheduling it as an automated task (e.g., every 15 minutes), it fails with this error:
OSError: Cannot save file into a non-existent directory: '/arcgis/home/nextbike'
import pandas as pd
# Load GeoJSON data
features = geojson_data['features']
# Extract desired columns including coordinates
data = []
for feature in features:
properties = feature['properties']
id = properties.get('id')
typ_stojanu = properties.get('typ_stojanu')
coordinates = feature['geometry']['coordinates']
x = coordinates[0]
y = coordinates[1]
data.append({'id': id, 'typ_stojanu': typ_stojanu, 'x': x, 'y': y})
# Convert to DataFrame
df = pd.DataFrame(data)
# Save to CSV
csv_file = r"/arcgis/home/nextbike/filtered_data.csv"
df.to_csv(csv_file, index=False)Problem:
The folder /arcgis/home/nextbike exists when I run the notebook manually.
The automated task fails at df.to_csv() with the directory error, even though the folder appears to exist.
What I’ve Tried:
Working Example:
import os
folder_path = r"/arcgis/home/nabijecky"
os.makedirs(folder_path, exist_ok=True)
df.to_csv(os.path.join(folder_path, "file.csv"))
Question:
Why does the automated task fail to recognize the directory, and how can I fix this?