Using DataFrames
GeoAnalytics Engine uses Spark DataFrames along with custom geometry data types to represent spatial data. A Spark DataFrame is like a Pandas DataFrame or a table in a relational database, but is optimized for distributed queries.
GeoAnalytics Engine comes with several DataFrame extensions for reading from spatial data sources like shapefiles and feature services, in addition to any data source that PySpark supports. When reading from a shapefile or feature service, a geometry column will be created automatically. For other data sources, a geometry column can be created from text or binary columns using GeoAnalytics Engine functions.
In this tutorial, you will learn how to create a DataFrame from your own definition, as well as from an existing file. You will also learn how to enable time and geometry for a DataFrame, and filter for certain records and columns.
Create a DataFrame
Set up the workspace
Import the required modules.
PythonUse dark colors for code blocks Copy
Create a DataFrame from an existing file
Specify an existing CSV file to create a DataFrame out of. The CSV contains GPS point readings with information like point ID, latitude and longitude, and a timestamp.
PythonUse dark colors for code blocks Copy Using your point definition created above, create a DataFrame with specified column names.
PythonUse dark colors for code blocks Copy Return and review the schema for your DataFrame.
PythonUse dark colors for code blocks Copy ResultUse dark colors for code blocks Copy
Create a DataFrame using your own definition
Create your own dataset definition containing values for ID, latitude and longitude information, and a timestamp.
PythonUse dark colors for code blocks Copy Create a DataFrame from the CSV using the headers as column names.
PythonUse dark colors for code blocks Copy Review your DataFrame. This should reflect the records in your CSV file.
PythonUse dark colors for code blocks Copy ResultUse dark colors for code blocks Copy
Set geometry and time for a DataFrame
Define geometry and time
For this example, geometry will be of type point defined by the columns latitude and longitude. The spatial reference ID for the coordinates is
4326
. Time is defined using the columnmytime
and the formatMM/dd/yyyy h:
. You will be able to use the result (m m: ss a df
) as a time- and geometry-enabled DataFrame for input to spatial and temporal functions.PythonUse dark colors for code blocks Copy ResultUse dark colors for code blocks Copy
Investigate and summarize your DataFrame
The examples below show common operations you can perform on DataFrames.
Summarize and understand your data
Create a DataFrame from an existing file.
PythonUse dark colors for code blocks Copy Get the count of rows within your DataFrame.
PythonUse dark colors for code blocks Copy ResultUse dark colors for code blocks Copy Generate a sample of your data.
PythonUse dark colors for code blocks Copy ResultUse dark colors for code blocks Copy Group your data based on column values.
PythonUse dark colors for code blocks Copy Calculate average, maximum, and minimum statistics for your grouped data.
PythonUse dark colors for code blocks Copy ResultUse dark colors for code blocks Copy
Filter and preview your data
Filter your data for records with a pressure value greater than or equal to 1000.
PythonUse dark colors for code blocks Copy Query your filtered result for the columns of interest. Using
.collect()
returns the values within the column as a list of row values and.show()
prints them out as a table.PythonUse dark colors for code blocks Copy ResultUse dark colors for code blocks Copy PythonUse dark colors for code blocks Copy ResultUse dark colors for code blocks Copy
What's next?
Learn more about how to set up your data and run tools and SQL functions: