【发布时间】:2019-11-17 12:14:12
【问题描述】:
有两个 shapefile 作为 GeoDataFrames 读入。对于每个 gdf 中的一列,我需要将值标准化为介于 0 和 1 之间。
我尝试使用scaler.fit_transform 函数对值进行规范化,但在传入二维数组而不是一维数组时引发了错误。所以我开始尝试(未成功)在规范化之前将列重塑(使用np.reshape)为一维数据帧。
output = gpd.read_file(r"C:\Users\mrich\OneDrive\GMU\Summer 2019 Comp Migration\output_3_simOutput.shp")
val = gpd.read_file(r"C:\Users\mrich\OneDrive\GMU\CSS 645 (Spring 2019)\Final Project\Other_geo_data\gadm36_TUR_1_val.shp")
# Reshape attributes
output.simEnd = np.reshape(output.simEnd, (928, -1)
val.val_mar19 = np.reshape(val.val_mar19, (928, -1)
# Normalize both actual and predicted REFPOP
scaler = preprocessing.StandardScaler()
scaled_actual = scaler.fit_transform(val.val_mar19)
scaled_predicted = scaler.fit_transform(output.simEnd)
要归一化的两列是 simEnd(在输出中)和 val_mar19(在 val 中)。每个条目有 928 个条目。我相信他们可能是 GeoSeries。
在重塑线中,Exception: Data must be 1-dimensional。
另一个错误但无法判断是否相关:AttributeError: 'Series' object has no attribute 'reshape.'
【问题讨论】:
标签: python-3.x numpy normalization sklearn-pandas geopandas