jupyter notebook 把shp文件某一列 由小数数据类型变为整数
时间: 2023-04-01 20:02:04 浏览: 60
可以使用 pandas 库中的 read_file() 函数读取 shp 文件,然后使用 astype() 函数将指定列的数据类型转换为整数类型。具体代码如下:
```python
import pandas as pd
# 读取 shp 文件
df = pd.read_file('your_shapefile.shp')
# 将指定列的数据类型转换为整数类型
df['your_column'] = df['your_column'].astype(int)
# 保存修改后的 shp 文件
df.to_file('your_modified_shapefile.shp')
```
注意,需要将 `your_shapefile.shp` 和 `your_modified_shapefile.shp` 替换为实际的文件名和路径,将 `your_column` 替换为需要转换数据类型的列名。
相关问题
jupyter notebook 导出shp文件
可以使用 geopandas 库来导出 shp 文件。首先需要安装 geopandas 库,然后在 jupyter notebook 中导入该库并读取数据,最后使用 to_file() 方法导出 shp 文件。具体操作可以参考以下代码:
```python
import geopandas as gpd
# 读取数据
data = gpd.read_file('data.geojson')
# 导出 shp 文件
data.to_file('data.shp', driver='ESRI Shapefile')
```
其中,data.geojson 是要导出的数据文件,data.shp 是导出的 shp 文件名。
jupyter notebook 按照列 合并多个shp文件
可以使用 geopandas 库来合并多个 shp 文件,具体步骤如下:
1. 使用 geopandas 的 read_file() 函数读取多个 shp 文件,得到多个 GeoDataFrame 对象。
2. 使用 pandas 的 concat() 函数将多个 GeoDataFrame 对象按照列合并成一个大的 GeoDataFrame 对象。
3. 使用 geopandas 的 to_file() 函数将合并后的 GeoDataFrame 对象保存为 shp 文件。
具体代码如下:
```python
import geopandas as gpd
import pandas as pd
# 读取多个 shp 文件
gdf1 = gpd.read_file('file1.shp')
gdf2 = gpd.read_file('file2.shp')
gdf3 = gpd.read_file('file3.shp')
# 合并多个 GeoDataFrame 对象
gdf = pd.concat([gdf1, gdf2, gdf3], axis=1)
# 保存合并后的 GeoDataFrame 对象为 shp 文件
gdf.to_file('merged.shp', driver='ESRI Shapefile')
```
希望能对你有所帮助!
相关推荐














