Select to view content in your preferred language

Creating temporary tables in memory

824
1
06-07-2023 05:57 AM
DylanW_TOC
New Contributor II

I'm creating a script tool that takes user input and exports those records cleans them in a temporary table and appends them to a separate table. The tool will be run daily so I was trying to set the environment to memory vs a scratch file geodatabase. In the code below it successfully runs up to line 19 where it throws the following error: FileNotFoundError: [Errno 2] No such file or directory: 'memory\temporary_table.csv'. I've tried setting "memory" to "in_memory" which results in the same error. This script is written for ArcGIS Pro 3.1 for reference. Any ideas on how to go about using memory or in_memory?

 

 

import arcpy
import pandas as pd

cleaned_lines = arcpy.GetParameterAsText(0)
cleaned_date = arcpy.GetParameterAsText(1)

# Create temporary directory
ws = "memory"
arcpy.env.scratchWorkspace = ws

# Set table variables
temp_table = ws+"\temporary_table.csv"
related_table = Related Table Path

# Export cleaned_lines
arcpy.conversion.ExportTable(cleaned_lines, temp_table)

# Drop unnecessary fields, clean date, and export csv
df = pd.read_csv(temp_table)
df2 = df[['OBJECTID','FACILITYID']]
df2['CLEANEDDATE'] = cleaned_date
df2.to_csv(temp_table)

# Append csv to related table
arcpy.management.Append(temp_table, related_table, "TEST")

# Delete temporary table
arcpy.Delete_management(temp_table)

 

 

0 Kudos
1 Reply
DanPatterson
MVP Esteemed Contributor

Write geoprocessing output to memory—ArcGIS Pro | Documentation

To write to the memory workspace, specify an output dataset path beginning with memory\ and with no file extension—for example, memory\tempOutput.

Use of memory-based workspaces in Python is only valid for geoprocessing tools. Memory is not a general-purpose virtual directory where you can write files or other data.

It doesn't like the "csv" portion


... sort of retired...
0 Kudos