import pandas as pd import numpy as np # 设置数据行数 total_rows = 100 # 总共100行 material_count = 61 # 前61行为材料 # 生成产品id product_ids = np.arange(1, total_rows + 1) # 生成种类,前61行是材料,后面是设备 categories = ['材料'] * material_count + ['设备'] * (total_rows - material_count) # 创建数据框 df_products = pd.DataFrame({ '产品id': product_ids, '种类': categories }) # 保存为CSV文件 file_path_products = '测试数据 products_materials_equipment.csv' df_products.to_csv(file_path_products, index=False) # index=False 不保存行索引 # 打印文件路径 print(f"CSV 文件已生成,路径为: {file_path_products}")