import pandas as pd import numpy as np # 设置随机种子 np.random.seed(42) num_companies = 170 # 企业ID范围 # 生成企业和设备数据 num_rows = 220 # 每个表的行数 company_ids = np.arange(num_companies) # 第二步:生成剩余的随机企业ID remaining_ids = np.random.randint(0, num_companies, size=num_rows - num_companies) # 合并两部分的企业ID all_company_ids = np.concatenate([company_ids, remaining_ids]) # 第三步:对企业ID进行升序排序 all_company_ids.sort() device_ids = np.random.randint(51, 107, size=num_rows) material_ids = np.random.randint(0, 51, size=num_rows) product_ids = np.random.randint(0, 107, size=num_rows) device_quantities = np.random.randint(50, 200, size=num_rows) material_quantities = np.random.randint(100,200, size=num_rows) product_quantities = np.random.randint(20, 100, size=num_rows) # 创建三个表格的数据框 df_devices = pd.DataFrame({ 'Firm_Code': all_company_ids, '设备id': device_ids, '设备数量': device_quantities }) df_materials = pd.DataFrame({ 'Firm_Code': all_company_ids, '材料id': material_ids, '材料数量': material_quantities }) df_products = pd.DataFrame({ 'Firm_Code': all_company_ids, '产品id': product_ids, '产品数量': product_quantities }) # 保存为CSV文件 df_devices.to_csv('测试数据 companies_devices.csv', index=False) df_materials.to_csv('测试数据 companies_materials.csv', index=False) df_products.to_csv('测试数据 companies_products.csv', index=False)