Home > Software engineering >  How to create a single rowed pandas dataframe with geopandas?
How to create a single rowed pandas dataframe with geopandas?

Time:01-20

I'm trying to export the lines from a polyline shapefile as individual shapefiles. When I am trying to loop through the rows of the gpd dataframe, it indicates that pd series do not have the attribute (to_file) which appears to be available for dataframes.

for i in range(0,5):
    dftemp = df.iloc[i,:]
    print(type(dftemp))
    dftemp.to_file(path   '//'   'z'   str(listi.value[0].split('.')[0])   '_'   str(i)   '.shp')

AttributeError: 'Series' object has no attribute 'to_file'

Thanks

CodePudding user response:

Try this:

for i in range(0,5):
    dftemp = df.iloc[[i],:]
    print(type(dftemp))
    dftemp.to_file(path   '//'   'z'   str(listi.value[0].split('.')[0])   '_'   str(i)   '.shp')

df.iloc[i,:] returns a Series, but df.iloc[[i],:] a GeoDataFrame, which is needed for to_file

  •  Tags:  
  • Related