Work with survey data

This notebook uses the ArcGIS API for Python. For more information, see the ArcGIS API for Python documentation and guides.

The ArcGIS API for Python provides an abundance of data analysis and data science workflows that can be deployed to perform a variety of tasks. The ArcGIS Survey123 module provides some foundational resources to get started working with your data.

The first step is to connect to your GIS.

import arcgis
from arcgis.gis import GIS
gis = GIS("home")

Next, a Survey Manager is defined, and a survey is accessed using the form's item ID. A survey in the Survey Manager is a single instance of a survey project that contains the item information and properties and provides access to the underlying survey dataset. For more information on Survey Manager, see the API Reference for the ArcGIS API for Python.

survey_manager = arcgis.apps.survey123.SurveyManager(gis)
survey_by_id = survey_manager.get("9f8e0a1c93454efe949cb3650614f465")
print(survey_by_id)
<Survey @ Campground Survey>

The ArcGIS Survey123 download method supports the following formats:

  • CSV
  • Shapefile
  • File Geodatabase
  • DF (pandas DataFrame)

The first three formats export your survey data to a file. Alternatively, you can create a pandas DataFrame directly in your notebook from your survey data.

The sample below defines those formats in a list, which is then iterated through. The data for the survey defined above is downloaded in each format in the list. The download method looks for the export format f and a folder directory to save the file to.

# Download - file formats
dl_formats = ['CSV', 'Shapefile', 'File Geodatabase']
for f in dl_formats:
    outfile = survey_by_id.download(f, "/tmp")
    print(outfile)
/tmp/aa06c4ca3170e432e9d38c5e237ef2076.zip
/tmp/a9f981eac293c475587b9bc4a42bbfc4c.zip
/tmp/afba38272e7ca4d8384e36a3cdb8311c4.zip

If you plan on continuing to work with your survey results using other ArcGIS API for Python tools, displaying your survey data as a pandas DataFrame directly in the notebook may help visualize your data as you progress.

# Download - pandas DataFrame
import pandas as pd
survey_df = survey_by_id.download('DF')
survey_df.head()
objectidglobalidreporttimecampgroundtotal_campsitestotal_equipment_campgroundCreationDateCreatorEditDateEditorSHAPE
01d45caefd-7aa8-4577-8f98-7ce387b091f32018-07-01 02:23:00A la minute11.02018-07-01 02:25:45.461999893NinjaMaster2018-07-10 18:10:11.171999931NinjaGreen{"x": -117.18188833333332, "y": 34.05562666666...
1291d9a73d-19a9-47be-8fb5-80da2cb4e6a32018-07-10 16:33:00None11.02018-07-10 16:34:30.994999886NinjaGreen2018-07-10 16:34:30.994999886NinjaGreen{"x": -117.16731128999994, "y": 32.70555832999...
23988dd421-40c9-4708-9c81-a685c8b04d9e2018-07-10 19:21:00Tt5512.02018-07-10 19:22:40.822999954NinjaGreen2018-07-10 19:22:40.822999954NinjaGreen{"x": -117.1631311580273, "y": 32.707366220594...
342802d970-2a8d-44f6-b9fc-bab022bfd81e2018-07-11 17:30:00None0NaN2018-07-11 17:30:50.607000113NinjaGreen2018-07-11 17:30:50.607000113NinjaGreen{"x": -117.1620025061552, "y": 32.707672144436...
458e1cc60e-6d37-4574-8763-035bf7c2676b2018-07-11 17:32:00None1NaN2018-07-11 17:33:07.476000071NinjaGreen2018-10-17 01:21:27.438999891NinjaGreen{"x": -117.16196038376653, "y": 32.70767375424...

Your browser is no longer supported. Please upgrade your browser for the best experience. See our browser deprecation post for more details.

You can no longer sign into this site. Go to your ArcGIS portal or the ArcGIS Location Platform dashboard to perform management tasks.

Your ArcGIS portal

Create, manage, and access API keys and OAuth 2.0 developer credentials, hosted layers, and data services.

Your ArcGIS Location Platform dashboard

Manage billing, monitor service usage, and access additional resources.

Learn more about these changes in the What's new in Esri Developers June 2024 blog post.

Close