我正在对熊猫的一些数据进行标准化处理,这些数据需要很长时间。不过,数学似乎相对简单,只有约2500行。有没有更快的方法?你知道吗
正如您在下面看到的,我已经手动完成了规格化。你知道吗
# normalize the rating columns to values between 0 and 1
df_1['numerator_norm'] = ((df_1['rating_numerator']- df_1['rating_numerator'].min())/(df_1['rating_numerator'].max()- df_1['rating_numerator'].min()))
df_1['denominator_norm'] = ((df_1['rating_denominator']- df_1['rating_denominator'].min())/(df_1['rating_denominator'].max()- df_1['rating_denominator'].min()))
df_1['normalized_rating'] = np.nan
for index, row in df_1.iterrows():
df_1['normalized_rating'][index] = (df_1['numerator_norm'][index] / df_1['denominator_norm'][index])
这将是一个很好的过程,只有几秒钟,而不是约60秒
更改:
收件人:
矢量化除法。你知道吗
Iterrows
是最好的避免,检查Does iterrows have performance issues?相关问题 更多 >
编程相关推荐