python - 如何将数据正确保存到列表中,然后在 python 中将其转换为 DataFrame?
问题描述
我有包含有关建筑物(Building_Number,几何)信息的 GeoDataFrame,我需要从中创建另一个 GeoDataFrame - 包含有关具有相同列(Building_Number,几何)的建筑物中心点(质心)的信息。
我的想法是首先创建一个空列表并将结果附加到列表中:
import geopadnas as gpd
result = []
centroids = gpd.GeoSeries(My_GDF.centroid)
result.append([My_GDF['Buliding_Number'],centroids])
print(result)
然而这对我不起作用,输出是:
[[0 61
1 5
2 22
3 NaN
4 7
5 NaN
6 NaN
7 5D
Name: BUI_NUMBER, dtype: object, 0 POINT (21.04572 52.14893)
1 POINT (21.02783 52.07371)
2 POINT (20.97048 52.22921)
3 POINT (20.93536 52.25316)
4 POINT (20.93575 52.25281)
5 POINT (20.93293 52.24256)
6 POINT (20.93444 52.24029)
7 POINT (20.93574 52.25361)
dtype: geometry]]
我想我需要这样的输出:
[[61, 5, 22, NaN, 7, NaN, NaN, 5D],[POINT (21.02783 52.07371, ..., POINT (20.93574 52.25361)]]
因为我想将它转换为 GeoDataFrame(这个,我知道该怎么做)。有什么方法可以按照我想要的方式将数据附加到列表中?或者,也许我可以将它从我现在得到的输出转换为 GDF?总结一下,我的想法是:
- 制作质心,然后创建一个包含有关建筑物编号和质心信息的列表
- 其次将其转换为 DataFrame:https ://datatofish.com/list-to-dataframe/
- 然后到 GeoDataFrame:https ://geopandas.org/gallery/create_geopandas_from_pandas.html
解决方案
像这样的东西对您创建新的 GeoDataFrame 有用吗?(顺便说一句,你在“bulding”键中有一个类型)
df = pandas.DataFrame(
{
'BuildingID': My_GDF['Buliding_Number']
#, centroids however those are put
}
)
gdf = geopandas.GeoDataFrame(df, geometry=geopandas.points_from_xy(df.Longitude, df.Latitude))
推荐阅读
- github-pages - 无法在正确的地址发布我的 github 页面
- arrays - 从颤动的数组中获取特定元素的索引路径
- python - 直接从文件夹中读取数据以在 keras 中进行训练
- amazon-web-services - 无法通过 AWS EC2 实例连接 RDS MYSQL 数据库,但显示错误(mysql: command not found)Mysql 已安装在实例上
- html - 将 pandas 框架显示为 csv 文件中的 html
- python - 从两个用 Poetry 导出同名包的项目导入
- gitlab - “无法获得 ci/pipeline_processing/atomic_processing_service::pipeline_id 的独家租约”是什么意思?
- angular - 从应用程序其他地方的延迟加载模块导入组件是否会规避 Angular 12 中该模块的延迟加载?
- flutter - Flutter:如何获得文件的幻数?
- c++ - 为什么c++代码运行时会新建一个exe文件是vscode,为什么这么大?