mesa/测试数据 产业-原材料消耗-产品生产量.py

43 lines
1.6 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import pandas as pd
import numpy as np
# 设置随机种子,确保结果可重复
np.random.seed(42)
# 定义产业数量
num_industries = 107
# 创建产业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])
# 创建两个数据框
df_consumed_materials = pd.DataFrame(consumed_materials_data, columns=['产业id', '消耗材料id', '消耗量'])
df_produced_products = pd.DataFrame(produced_products_data, columns=['产业id', '制造产品id', '制造量'])
# 保存两个数据框为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)