Python Forum

Full Version: Pandas Tutor for geopandas
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pandas Tutor can't import the geopandas library. I'm trying to understand a short function.
def dauphin_precs(row):
    nm = row['MCD_NAME']
    if row['WARD']:
        nm = nm + ' ' + row['WARD']
    if row['PRECINCT']:
        nm = nm + ' ' + row['PRECINCT']
    return nm
dauphin_gdf = geopandas.read_file('/Users/admin/Desktop/PA/2018/map/Voting_Districts-shp')
dauphin_gdf['original_precinct_name'] = dauphin_gdf.apply(lambda row: dauphin_precs(row), axis=1)
To avoid line 8 causing an error (without importing geopandas), can it be replaced with the inputted table (attached)? If yes, how? Thanks.
Did you try importing with pandas rather than geopandas? In your code so far does not look like you are using anything special from geopandas.
I've figured out the question in my original post (line 8 used geopandas.read_file). Pandas Tutor can't import geopandas, but it can import io.