import numpy as np
import pandas as pd
import pickle
import re
from scipy.optimize import minimize
import random
import matplotlib.pyplot as plt
import scipy.stats as stats
from concurrent.futures import ThreadPoolExecutor
# 加载数据,添加文件存在性验证
def load_data():
try:
with open('fited_weight_2018.pkl', 'rb') as f:
fited_weight = pickle.load(f)
with open('BothExit_symbol_2018.pkl', 'rb') as f:
both_exit_symbol = pickle.load(f)
df_profit = pd.read_csv('./PT_LCMAINFIN_new.csv', header=0)
df_profit = df_profit.dropna(subset=['IndustryCode'])
df_profit['IndustryCode'] = df_profit['IndustryCode'].astype(float).astype(int)
df_profit['EndDate'] = df_profit['EndDate'].str.slice(0, 4)
df_profit = df_profit[["Symbol", "EndDate", "IndustryCode", "TotalAssets", "OperatingCost", "OperatingEvenue"]]
df_profit['EndDate'] = df_profit['EndDate'].astype(float).astype(int)
df_profit_2018 = df_profit[df_profit['EndDate'] == 2018]
df = pd.read_csv('D:\\碳文献\\碳价\\汇总数据\\上市公司行业分类.csv', header=0)
df_employ = pd.read_csv('./13.csv', header=0)
df_employ = df_employ.dropna(subset=['Employment'])
return fited_weight, both_exit_symbol, df_profit_2018, df, df_employ
except FileNotFoundError as e:
print(f"文件未找到: {
e}")
raise
# 初始化粒子
def enable(particles):
for particle in particles:
particle['weight'] = np.array(rand_weight())
particle['pbest'] = particle['weight']
particle['v'] = np.array([0.0001] * 4)
return particles
# 生成随机权重
def rand_weight():
weights = np.random.uniform(0
标签:EndDate,weight,python,profit,df,import,DEA,csv,优化
From: https://blog.csdn.net/max500600/article/details/145043382