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.

Input
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.

Input
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.

Input
# 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.

Input
# Download - pandas DataFrame
import pandas as pd
survey_df = survey_by_id.download('DF')
survey_df.head()
Output
objectid globalid reporttime campground total_campsites total_equipment_campground CreationDate Creator EditDate Editor SHAPE
0 1 d45caefd-7aa8-4577-8f98-7ce387b091f3 2018-07-01 02:23:00 A la minute 1 1.0 2018-07-01 02:25:45.461999893 NinjaMaster 2018-07-10 18:10:11.171999931 NinjaGreen {"x": -117.18188833333332, "y": 34.05562666666...
1 2 91d9a73d-19a9-47be-8fb5-80da2cb4e6a3 2018-07-10 16:33:00 None 1 1.0 2018-07-10 16:34:30.994999886 NinjaGreen 2018-07-10 16:34:30.994999886 NinjaGreen {"x": -117.16731128999994, "y": 32.70555832999...
2 3 988dd421-40c9-4708-9c81-a685c8b04d9e 2018-07-10 19:21:00 Tt55 1 2.0 2018-07-10 19:22:40.822999954 NinjaGreen 2018-07-10 19:22:40.822999954 NinjaGreen {"x": -117.1631311580273, "y": 32.707366220594...
3 4 2802d970-2a8d-44f6-b9fc-bab022bfd81e 2018-07-11 17:30:00 None 0 NaN 2018-07-11 17:30:50.607000113 NinjaGreen 2018-07-11 17:30:50.607000113 NinjaGreen {"x": -117.1620025061552, "y": 32.707672144436...
4 5 8e1cc60e-6d37-4574-8763-035bf7c2676b 2018-07-11 17:32:00 None 1 NaN 2018-07-11 17:33:07.476000071 NinjaGreen 2018-10-17 01:21:27.438999891 NinjaGreen {"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.