补充9月数据

main
鸽子 1 year ago
parent e2b9fd1086
commit 9e36474ba2

@ -4,21 +4,59 @@ import re
file_dir1 = r'C:\Users\鸽子\Desktop\一版结果\电压等级电量预测结果\偏差率'
file_dir2 = r'C:\Users\鸽子\Desktop\一版结果\电压等级电量预测结果\月底3天预测结果'
file_dir3 = r'C:\Users\鸽子\Desktop\一版结果\行业电量预测结果\偏差'
print(os.listdir(file_dir3))
str1 = '丽水电压等级10kv以下月底偏差率:0.00229'
print(re.split('电压等级|月底偏差率:',str1))
with open(os.path.join(file_dir3,'9月底偏差率.txt'),'r',encoding='utf-8') as f:
lines = f.readlines()
list_city = []
list_industry = []
list_loss = []
for i in lines:
i = re.split(':||其中', i)
print(i)
list_city.append(i[0][:2])
list_industry.append(i[-2].replace(i[0][:2],''))
list_loss.append(i[-1][:-2])
df_level = pd.DataFrame({'城市':list_city,'行业':list_industry,'偏差':list_loss})
df_level.to_csv(os.path.join(file_dir3,'9月底偏差率.csv'),encoding='gbk')
print(df_level)
import numpy as np
np.set_printoptions(threshold=np.inf)
# print(os.listdir(file_dir3))
# str1 = '丽水电压等级10kv以下月底偏差率:0.00229'
#
# print(re.split('电压等级|月底偏差率:',str1))
# with open(os.path.join(file_dir3,'9月底偏差率.txt'),'r',encoding='utf-8') as f:
# lines = f.readlines()
# list_city = []
# list_industry = []
# list_loss = []
# for i in lines:
# i = re.split(':||其中', i)
# print(i)
# list_city.append(i[0][:2])
# list_industry.append(i[-2].replace(i[0][:2],''))
# list_loss.append(i[-1][:-2])
# df_level = pd.DataFrame({'城市':list_city,'行业':list_industry,'偏差':list_loss})
# # df_level.to_csv(os.path.join(file_dir3,'9月底偏差率.csv'),encoding='gbk')
# print(df_level)
file_dir = r'C:\python-project\pytorch3\浙江行业电量\浙江所有地市133行业数据'
# print(os.listdir(file_dir))
dict1 = {}
for file in os.listdir(file_dir):
df = pd.read_excel(os.path.join(file_dir,file),index_col=' stat_date ')
col_list = df.drop(columns=[i for i in df.columns if (df[i] == 0).sum() / len(df) >= 0.5]).columns
dict1[file[:2]] = col_list
print(dict1)
# print(len(df.drop(columns=[i for i in df.columns if (df[i] == 0).sum() / len(df) >= 0.5]).columns))
read_path = r'C:\Users\鸽子\Desktop\一版结果\行业电量预测结果\月底预测结果'
list1 = []
for i in os.listdir(read_path):
print(i)
data = pd.read_csv(os.path.join(read_path, i), sep='\t',header=None)
data = data[data.columns[1:]]
for j,step in enumerate(range(0, len(data), 4)):
df = data.iloc[step+1:step + 4, :]
df.columns = ['预测值', '实际值', '偏差率']
try:
df['行业'] = dict1[i[2:4]][j]
except:
pass
df['城市'] = i[2:4]
list1.append(df)
print(df)
df = pd.concat(list1,ignore_index=True)
df.to_csv('各市行业电量预测结果.csv',encoding='gbk')
print(df)
Loading…
Cancel
Save