淘宝做网站很便宜,建设银行手机版官方网站下载,深圳公司注册名称查询,wordpress个人站无法升级如何在完成聚类分析后按聚类编号保存数据并且带上原数据所属ID
# 将每个聚类的数据保存到不同的文件中
for cluster_id in range(6): # 假设共有6个聚类cluster_data data[data[cluster] cluster_id]cluster_data_with_customer_id cluster_data.copy()cluster_data_with_…如何在完成聚类分析后按聚类编号保存数据并且带上原数据所属ID
# 将每个聚类的数据保存到不同的文件中
for cluster_id in range(6): # 假设共有6个聚类cluster_data data[data[cluster] cluster_id]cluster_data_with_customer_id cluster_data.copy()cluster_data_with_customer_id[CustomerID] data.loc[cluster_data.index, CustomerID]cluster_data_with_customer_id.to_excel(fcluster_{cluster_id}_data.xlsx, indexFalse) # 将数据保存为Excel文件文件名包含聚类编号并包含CustomerID列
在保存聚类分析结果时我希望带上每条数据原来所属的CustomerID方便后续添加对应的数据进行分析结果报错KeyError: CustomerID。
这是因为我读取原数据中没有包含CustomerID列导致dataframe里面没有CustomerID。
解决
在读取数据的时候加入CustomerID列