You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

24 lines
912 B
Python

import os
import pandas as pd
df = pd.read_csv(r'C:\Users\鸽子\Desktop\浙江各区县数据(2).csv')
df.columns = df.columns.map(lambda x:x.strip())
df[''] = df[''].str[:2]
df = df[['','org_name','日期','0.4kv及以下']]
df['日期'] = pd.to_datetime(df['日期'])
print(df)
wd_file = 'C:\python-project\p1031\入模数据'
df_wd = pd.DataFrame({})
for city in os.listdir(wd_file):
data = pd.read_excel(os.path.join(wd_file,city)).drop(columns='售电量')
data['city_name'] = data['city_name'].str[:2]
df_wd = pd.concat([df_wd,data])
print(df_wd)
df_wd['dtdate'] = pd.to_datetime(df_wd['dtdate'])
df = pd.merge(df,df_wd,left_on=['日期',''],right_on=['dtdate','city_name'])
df = df[['city_name','org_name','dtdate','tem_max','tem_min','holiday','24ST','0.4kv及以下']]
df['0.4kv及以下'] /= 10000
df.to_csv('区县400v入模数据.csv',index=False,encoding='GBK')
print(df)