I am looking for the equivalent argument to pandas.read_csv(index_col='column')
in the geopandas.read_file()
function. My goal is to read a shapefile and specify the index column. However, the following does not set any index column and returns the same GeoDataframe
as calling the function without the argument:
import geopandas as gpd
gdf = gpd.read_file('test.shp', index_col='column')
The documentation of the read_file
function does not list index_col
as an argument and states that one can specify keyword arguments that are going to be passed to the fiona.open
function (but not to any pandas.read_*
function).
A workaround is to use the set_index()
method after reading the file:
import geopandas as gpd
gdf = gpd.read_file('test.shp')
gdf = gdf.set_index('column')
# or
gdf = gpd.read_file('test.shp').set_index('column')
However, it feels like specifying the index should be possible directly from the read_file
function.
set_index()
is the best option so far.