Introduction to Python

Example Python script

Copy the following lines into a Jupyter Notebook one at a time. Then, fill in the lines with the instructor and run them.

# import a module

# import a module with an alias

# declare a numeric variable

# view the contents of a variable

# create a list and store it in a variable

# get the length of a list

# extract an element from a variable

# use a function

# look up documentation about a function

# read a spatial dataset from the internet
# url = "https://raw.githubusercontent.com/mhaffner/data/master/bayfield_water.geojson"

# view various geopandas attributes (area, geom_type)

# use various geopandas methods (plot, to_crs, buffer)

# check the type of an object

# view a single column

# extract certain rows from a data frame

# extract certain columns from a data frame

# set the working directory to an existing folder