|
|
|
@ -19,10 +19,12 @@ print(df.columns)
|
|
|
|
|
|
|
|
|
|
print(dict(zip(df.columns,[(df[x]==0).sum()/len(df) for x in df.columns])))
|
|
|
|
|
yc_org_list = []
|
|
|
|
|
list_fl = []
|
|
|
|
|
list_org = []
|
|
|
|
|
for city in df['市'].drop_duplicates():
|
|
|
|
|
df_ct = df[df['市']==city]
|
|
|
|
|
wb = Workbook()
|
|
|
|
|
wb.save(fr'C:\Users\鸽子\Desktop\9月0.4kv区县预测\{city}.xlsx')
|
|
|
|
|
# wb = Workbook()
|
|
|
|
|
# wb.save(fr'C:\Users\鸽子\Desktop\9月0.4kv区县预测\{city}.xlsx')
|
|
|
|
|
for org in df_ct['org_name'].drop_duplicates():
|
|
|
|
|
if org.strip()[-4:] != '供电公司':
|
|
|
|
|
continue
|
|
|
|
@ -42,12 +44,12 @@ for city in df['市'].drop_duplicates():
|
|
|
|
|
dd['ds'] = pd.to_datetime(dd['ds'])
|
|
|
|
|
|
|
|
|
|
# 划分数据,划分为训练集和验证集,预测的数据设置为未来3天
|
|
|
|
|
df_train = dd[(dd['ds']>='2022-01-01')&(dd['ds']<='2023-09-30')][:-3]
|
|
|
|
|
df_train = dd[(dd['ds']>='2022-01-01')&(dd['ds']<='2023-07-31')][:-3]
|
|
|
|
|
df_train = df_train.loc[normal(df_train['y']).index]
|
|
|
|
|
if df_train.shape[0] <= 180:
|
|
|
|
|
yc_org_list.append(org)
|
|
|
|
|
continue
|
|
|
|
|
df_test = dd[(dd['ds']>='2022-01-01')&(dd['ds']<='2023-09-30')][-3:]
|
|
|
|
|
df_test = dd[(dd['ds']>='2022-01-01')&(dd['ds']<='2023-07-31')][-3:]
|
|
|
|
|
# 数据的变动会受到季节、周、天的影响,存在一定的规律性,因此我们将这三个参数设置为True
|
|
|
|
|
model = Prophet(yearly_seasonality=True, weekly_seasonality=True, daily_seasonality=True)
|
|
|
|
|
# 采用中国的假期模式,其余参数均保持默认
|
|
|
|
@ -78,15 +80,22 @@ for city in df['市'].drop_duplicates():
|
|
|
|
|
df_all['偏差率'] = (df_all['y'] - df_all['yhat'])/df_all['y']
|
|
|
|
|
df_all.rename(columns={'y':'真实值','yhat':'预测值'},inplace=True)
|
|
|
|
|
df_all = df_all[['org_name','真实值','预测值','偏差率']]
|
|
|
|
|
|
|
|
|
|
list_org.append(org)
|
|
|
|
|
try:
|
|
|
|
|
result = df_all.loc['2023-9']
|
|
|
|
|
result = df_all.loc['2023-7']
|
|
|
|
|
result['goal'] = (result['真实值'] - result['预测值'])[-3:].sum()/result['真实值'].sum()
|
|
|
|
|
with pd.ExcelWriter(fr'C:\Users\鸽子\Desktop\9月0.4kv区县预测\{city}.xlsx',mode='a',engine='openpyxl',if_sheet_exists='replace') as writer:
|
|
|
|
|
result.to_excel(writer,sheet_name=f'{org}')
|
|
|
|
|
list_fl.append((result['真实值'] - result['预测值'])[-3:].sum()/result['真实值'].sum())
|
|
|
|
|
|
|
|
|
|
# with pd.ExcelWriter(fr'C:\Users\鸽子\Desktop\9月0.4kv区县预测\{city}.xlsx',mode='a',engine='openpyxl',if_sheet_exists='replace') as writer:
|
|
|
|
|
# result.to_excel(writer,sheet_name=f'{org}')
|
|
|
|
|
except:
|
|
|
|
|
yc_org_list.append(org)
|
|
|
|
|
|
|
|
|
|
print(yc_org_list)
|
|
|
|
|
df = pd.DataFrame({'org':list_org,'goal':list_fl})
|
|
|
|
|
print(df)
|
|
|
|
|
print(df['goal'].value_counts(bins=[-0.05,-0.01,-0.005,0, 0.005, 0.01, 0.02,0.05],sort=False))
|
|
|
|
|
# print(yc_org_list)
|
|
|
|
|
# # 创建一个ExcelWriter对象
|
|
|
|
|
# with pd.ExcelWriter(r'C:\Users\鸽子\Desktop\output.xlsx',mode='a',if_sheet_exists='replace') as writer:
|
|
|
|
|
# # 将不同的子文件写入同一个Excel文件的不同工作表
|
|
|
|
|