Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |
Tags
- 위내시경
- 신당동한우
- 튀르키예환전
- 중구사랑상품권
- 경량보스턴백
- TNE목배게
- 터키택시미터기
- 페이북
- TDay
- 건강검진
- kmi
- 튀르키예택시
- 대장내시경
- 내돈내산
- 포켓몬고
- 이스탄불택시사기
- 터키택시
- SKT
- Mode
- 터키택시사기
- 양재동맛집
- 이스탄불택시
- 수면위내시경
- 수면대장내시경
- SQL
- 택시바가지
- 캐리어보스턴백
- 부모님모시고오기좋은음식점
- 네이버머니포인트카드
- 카보목배게
Archives
- Today
- Total
집순이 놀이터
집에서하자 _ 등록 차량 데이터 정제 2 본문
#python 3.0
import pandas as pd
import openpyxl
from datetime import datetime
#파일명
filename = 'D:/data/자동차_등록_현황/1차가공/202101.xlsx'
#파일명 변수화
directory = 'D:/data/자동차_등록_현황/1차가공/'
all_data = pd.DataFrame(columns =['year','month','type','city','전기','총계'])
#
#연도별 파일 호출.
for year in range(2021,2023) :
for month in range(1,13):
m = format(month,'02')
#print(directory + str(year) +'년_'+ m + postfile)
filename = directory + str(year)+ m +'.xlsx'
total = set_df_2(year,month,filename)
all_data = all_data.append(total, ignore_index = True)
#
def set_df_2(year,month,filename):
df = pd.read_excel(filename,
engine = 'openpyxl',
header = 1)
removeidx = df[df['연료별']=='시도별'].index
df.drop(removeidx,inplace=True)
df.rename(columns={'연료별':'city'},inplace=True)
newdf = df[['city','전기','총계']]
newdf['type'] = '승용'
newdf
newdf1 = df[['city','전기.1','총계.1']]
newdf1['type'] = '승합'
newdf1.rename(columns={'전기.1':'전기'},inplace=True)
newdf1.rename(columns={'총계.1':'총계'},inplace=True)
newdf1
newdf2 = df[['city','전기.2','총계.2']]
newdf2['type'] = '화물'
newdf2.rename(columns={'전기.2':'전기'},inplace=True)
newdf2.rename(columns={'총계.2':'총계'},inplace=True)
newdf2
newdf3 = df[['city','전기.3','총계.3']]
newdf3['type'] = '특수'
newdf3.rename(columns={'전기.3':'전기'},inplace=True)
newdf3.rename(columns={'총계.3':'총계'},inplace=True)
newdf3
#최초 1번
total = newdf
total = total.append(newdf1, ignore_index = True)
total = total.append(newdf2, ignore_index = True)
total = total.append(newdf3, ignore_index = True)
total['year'] = year
total['month'] = month
return total
# total.to_excel(excel_writer ='D:/data/자동차_등록_현황/2차가공/'+str(year)+month+'.xlsx')