2024-09-20 09:26:39 +08:00
|
|
|
|
import pandas as pd
|
|
|
|
|
import numpy as np
|
|
|
|
|
|
|
|
|
|
# 设置随机种子,确保结果可重复
|
|
|
|
|
np.random.seed(42)
|
|
|
|
|
|
|
|
|
|
# 定义产业数量
|
2024-09-21 22:39:09 +08:00
|
|
|
|
num_industries = 107
|
2024-09-20 09:26:39 +08:00
|
|
|
|
|
|
|
|
|
# 创建产业ID列表
|
|
|
|
|
industry_ids = [i for i in range(0, num_industries + 1)]
|
|
|
|
|
|
|
|
|
|
# 为每个产业生成随机的材料id、消耗量、产品id和制造量
|
|
|
|
|
consumed_materials_data = []
|
|
|
|
|
produced_products_data = []
|
|
|
|
|
|
|
|
|
|
for industry in industry_ids:
|
|
|
|
|
# 每个产业消耗的材料(生成1到3个随机材料ID和消耗量)
|
|
|
|
|
num_materials = np.random.randint(1, 4)
|
|
|
|
|
for _ in range(num_materials):
|
|
|
|
|
material_id = np.random.randint(0, 100)
|
|
|
|
|
consumption_quantity = np.random.randint(50, 500)
|
|
|
|
|
consumed_materials_data.append([industry, material_id, consumption_quantity])
|
|
|
|
|
|
|
|
|
|
# 每个产业制造的产品(生成1到3个随机产品ID和制造量)
|
|
|
|
|
num_products = np.random.randint(1, 4)
|
|
|
|
|
for _ in range(num_products):
|
|
|
|
|
product_id = np.random.randint(100, 201)
|
|
|
|
|
production_quantity = np.random.randint(100, 1000)
|
|
|
|
|
produced_products_data.append([industry, product_id, production_quantity])
|
|
|
|
|
|
|
|
|
|
# 创建两个数据框
|
2024-09-21 22:39:09 +08:00
|
|
|
|
df_consumed_materials = pd.DataFrame(consumed_materials_data, columns=['产业id', '消耗材料id', '消耗量'])
|
|
|
|
|
df_produced_products = pd.DataFrame(produced_products_data, columns=['产业id', '制造产品id', '制造量'])
|
2024-09-20 09:26:39 +08:00
|
|
|
|
|
|
|
|
|
# 保存两个数据框为CSV文件
|
|
|
|
|
file_path_consumed = '测试数据 consumed_materials.csv'
|
|
|
|
|
file_path_produced = '测试数据 produced_products.csv'
|
|
|
|
|
|
|
|
|
|
df_consumed_materials.to_csv(file_path_consumed, index=False)
|
|
|
|
|
df_produced_products.to_csv(file_path_produced, index=False)
|
|
|
|
|
|