如何最有效地将geopandas geodataframe转换为pandas dataframe?以下是我使用的方法,是否有其他更有效或更好的方法可以避免生成错误呢?
什么是将geopandas geodataframe转换为pandas dataframe的最有效方法?以下是我使用的方法,是否有其他方法更有效或更好地避免产生错误?
import geopandas as gpd
import pandas as pd
# assuming I have a shapefile named shp1.shp
gdf1 = gpd.read_file('shp1.shp')
# then for the conversion, I drop the last column (geometry) and specify the column names for the new df
df1 = pd.DataFrame(gdf1.iloc[:,:-1].values, columns = list(gdf1.columns.values)[:-1] )
gdf.drop(columns='geometry')
中的columns
关键字只适用于较新的 pandas 版本0.21及以上。对我来说它不起作用,对其他人也可能不起作用。 - jberriogdf.drop('geometry', axis=1)
,我会加上这个。 - joris