0

I've created a script tool in ArcGIS Pro that asks the user to select a csv file, and then reads that csv file into a pandas DataFrame and performs some calculations. I'd like to be able to export a new csv file after the calculations are complete in the same folder as the input csv file.

For example, the user selects the input csv file from (C:\Users\Luis\GIS\input.csv). I'd like to export a new csv at the end of the script to (C:\Users\Luis\GIS\output.csv)

The parameter that reads in the user input is set up as follows:

input_csv = arcpy.GetParameterAsText(0)

The data type for this parameter is File is the Tool Properties in ArcGIS Pro.

1 Answer 1

1

If all you want is to get the folder the input file is in and the input_csv parameter is an absolute path you can use the following

input_csv = arcpy.GetParameterAsText(0)
output_csv = input_csv.split('\\')[:-1]
output_csv = '\\'.join(output_csv + ['output.csv'])

Then save your DataFrame using the new filepath

df.to_csv(output_csv) 
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.