본문 바로가기

Python

(36)
파이썬으로 엑셀 자료 이동하여 그래프를 그려보자 1. 출발점 시계열 데이터가 있다. 일반적으로 5년 평균 그래프를 자주 그리는데 월이 1월로 고정되는 문제점(?)이 있다. 농산물의 경우 시즌 개념이 적용되기 때문에 (원당의 경우(10월~9월)) 시즌을 고정하여 데이터를 배치하고 그래프를 그려보고 싶다. 2. 무식한 코드 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667import pandas as pdimport numpy as npimport sysfrom openpyxl import load_workbook sys.path.append("C:\\pytest")df = pd.r..
파이썬 엑셀 loop 시트 생성 하나의 엑셀 파일에(워크북) 엑셀 시트별로 동일한 형태의 자료가 있을 때 동일한 함수나 수식을 적용한 워크북을 시트별로 생성하고 싶을 때 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 import openpyxl import pandas as pd import sys from openpyxl import load_workbook sys.path.append("C:\\pytest") xlsxFile = 'C:\\pytest\\commoditydata.xlsx' wb = openpyxl.load_workbook(xlsxFile) # 시트 이름 확인하기 wb.sheetnames # 시트 데이터 가져와서 시트별로 저장하기 for item i..
리스트 컴프리헨션(list comprehension) 1 2 3 4 5 6 7 8 # 왼쪽에서 오른쪽으로 진행되면서 실행된다. matrix = [[1,2,3], [4,5,6], [7,8,9]] print(matrix) matrix_row_element = [row_element for row in matrix for row_element in row] print(matrix_row_element) [[1, 2, 3], [4, 5, 6], [7, 8, 9]] [1, 2, 3, 4, 5, 6, 7, 8, 9] Colored by Color Scripter cs 리스트 컴프리헨션 자꾸 까먹어서 정리할 겸. 처음 for 앞에 있는 row_element는 당연하겠지만 두번째 for 뒤에 있는 row_element와 같다. 일반적으로 리스트 컴프리핸션 실행 순서는 왼..
EIA python API 1. 원유를 조금이라도 분석해본 사람이면 EIA 데이터의 유효성을 안다. 많은 데이터를 API 통해 python으로 불러와보자. 2. EIA API 등록 https://www.eia.gov/opendata/ https://www.eia.gov/opendata/ The Google Sheets Add-on feature is currently down for maintenance. Thank you for your patience. The U.S. Energy Information Administration is committed to enhancing the value of its free and open data by making it available through an Application Prog..
ValueError: cannot reindex from a duplicate axis https://stackoverflow.com/questions/53622190/valueerror-cannot-reindex-from-a-duplicate-axis-when-assigning-new-column-to-pa ValueError: cannot reindex from a duplicate axis when assigning new column to pandas DataFrame Im trying to figure out what hours in my datetime index are between 2 different hours. This is my code: rbe60['result'] = rbe60.index.hour.to_series().between(3,23) The only prob..
모델 평가지표 1. Forecast quality metrics 모델을 만들고 만들어진 모델의 유효성과 성과를 판단할 때 사용되는 평가지표는 아래와 같다. MAE (Mean Absolue Error) MAPE (Mean Absolue Percentage Error) MSE (Mean Squared Error) MeaAE (Median Absolue Error) RMSE (Root Mean Squared Error) MSLE (Mean Squared Log Error) RMSLE (Root Mean Squared Log Error) R² (R Sqaure) 보다 구체적인 계산 방법과 라이브러리 코드는 다음 페이지를 참조하면 된다. https://bkshin.tistory.com/entry/%EB%A8%B8%EC%8B%A..
엑셀 워크북의 웍크시트 데이터 병합 1. 하나의 엑셀 파일에(워크북)에 여러가지 시트에 데이터가 존재할 경우 병합하는 방법 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 import openpyxl import pandas as pd import sys from openpyxl import load_workbook location = os.getcwd() sys.path.append("C:\\pytest") xlsxFile = 'C:\\pytest\\commoditydata.xlsx' sheetList = [] # openpyxl를 이용하여 시트명 가져오기 wb = openpyxl.load_workbook(xlsxFile) for i in wb.sheetnames..
investing.com 데이터 장기 시계열 데이터 등이 필요할 때가 있어서 찾아보면 막상 찾기 어려울 때가 있다. https://investpy.readthedocs.io/index.html Welcome to investpy’s documentation! — investpy 0.9.14 documentation © Copyright 2018-2020, Alvaro Bartolome Revision 865d530b. investpy.readthedocs.io investing.com 데이터를 가져올 수 있는 라이브러리.