#import module and shapefile
import geopandas as gpd
df = gpd.read_file("C:\data\mtbs_fod_pts_data\mtbs_fod_pts_20170501.shp")
#display GeoDataFrame, looks just like pandas dataframe
df.head()
# components of GeoDataFrame object follow those of pandas dataframes.
#Here, all GeoDataframe attributes are set to their own variable
index = df.index
columns = df.columns
data = df.values
index # returns number of rows as tuple. is referred to as "row index"
columns # "column index"
data # returns attributes for all rows
#RangeIndex is a special type of index object analogous to a Python range object,
#saving memory by only printing stop start and step values
type(index)
type(columns)
type(data) # all three are exactly the same as with a pandas dataframe.
#print data types per column. mostly objects because attribute tables from shapefiles contain text as well as numbers
df.dtypes.head()
# count all different data types
df.get_dtype_counts()
# print type of column, returns pandas Series object
type(df['FIRENAME'])
# compare different types of columns data
firename = df['FIRENAME'] #object type
fireyear = df['FIRE_YEAR'] #float64 type
# for object, returns sum of counts
firename.value_counts().head()
# returns counts per year
fireyear.value_counts().head()
# describe method used on object type
firename.describe()
# describe method used on float64 type, returns more statistics as expected with numerical values
fireyear.describe()
# returns boolean and checks if value is null
firename.isnull().head()
fireyear.isnull().head()
# checks if there are NAN values in column
firename.hasnans
fireyear.hasnans
# checks if there are 0 values in column, returns boolean
fireyear.notnull().head()
# checks if row value corresponds with a certain value
firename = df['FIRENAME']
firename == "UNNAMED"
# example of chaining methods
fireyear.isnull().sum()
# set a different column as index, in this case "FIRENAME"
df2 = df.set_index('FIRENAME')
df2.head()