Conclusion

We have covered a lot of ground in this text. In the first part, we explored the foundations of the Python language: variables, data types, and data models; functions, loops, and control flow; list comprehension and f-strings; classes; modules; and working with files and directories. We then applied these skills to data science tasks. We worked with multidimensional arrays using NumPy and labeled arrays using Xarray; read, queried, summarized, and joined data tables with Pandas and Polars; built and refined graphs with matplotlib, Seaborn, and Pandas; and performed statistical inference using theory-based and simulation-based methods with SciPy and Statsmodels. We also moved beyond interactive code and built a documented script that accepts user-provided arguments using argparse and can be run from the command line. In the second part, we applied these skills to geospatial data: we made static and interactive maps; performed vector geoprocessing with GeoPandas; processed raster grids, multispectral imagery, and digital terrain models with Rasterio, NumPy, and SciPy; searched for and downloaded analysis-ready satellite and elevation data using STAC and pystac-client; accessed external geospatial software using the whitebox library to run WhiteboxTools; and characterized point patterns, spatial autocorrelation, and hot spots using libpysal and esda. In the final part, we explored metrics for assessing regression and classification models; fit, interpreted, and diagnosed linear regression models with Statsmodels and used them to make a spatial prediction of burn severity; implemented the random forest algorithm for a geospatial prediction problem using scikit-learn and compared it to a support vector machine with hyperparameters tuned using cross validation and explored interpretable machine learning using the explainable boosting machine method made available in InterpretML.

A key benefit of Python is that all of these tasks can be completed in a single environment. Data can be read, cleaned, processed, analyzed, visualized, and modeled using code, which makes workflows reproducible, documented, and easy to update or apply to new data or study areas. Many of the libraries explored in this text are built on top of each other. For example, Pandas, Xarray, and Rasterio rely on NumPy arrays, GeoPandas is built on Pandas, Seaborn and Pandas graphing are built on matplotlib, and scikit-learn expects data stored as NumPy arrays or Pandas DataFrames. We hope you have started to see how these tools fit together.

As with any language, the best way to improve your Python skills is to practice. We encourage you to apply the methods discussed here to your own data and problems. You will run into issues not covered in this text. Fortunately, Python has a large and active user community, and help is readily available through package documentation, tutorials, and online forums. If you would like to continue learning, we recommend Python for Data Analysis by Wes McKinney, the creator of Pandas, and Geographic Data Science with Python by Rey, Arribas-Bel, and Wolf, both of which are freely available online. If you would like to use Quarto to combine your code, results, and writing into reproducible reports, websites, or books, as we did to create this text, we recommend Quarto for Scientists by Nicholas Tierney. If you are interested in using Python for deep learning, our companion text, Geospatial Deep Learning with Python and PyTorch, builds on the material presented here.

Thank you for working through this text. We hope that it has provided you with a solid foundation for working with and analyzing data, including geospatial data, in Python. We would also like to thank AmericaView for supporting the development of this text and its mission of advancing Earth observation education.