■ read_excel 함수의 index_col/na_values 인자를 사용해 EXCEL 파일 데이터를 로드하는 방법을 보여준다.
▶ main.py
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 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
import pandas as pd import numpy as np datetimeIndex = pd.date_range("2000/01/01", periods = 1000) dataFrame1 = pd.DataFrame( np.random.randn(1000, 4), index = datetimeIndex, columns = ["A", "B", "C", "D"] ) dataFrame1.to_excel("test.xlsx", sheet_name = "Sheet1") print(dataFrame1) """ A B C D 2000-01-01 0.053874 0.285479 2.200199 -0.497760 2000-01-02 0.382564 0.032303 2.176588 0.970032 2000-01-03 -0.960918 0.380824 -0.187437 -0.691698 2000-01-04 -0.854058 -1.280247 -1.469207 -1.037654 2000-01-05 0.141451 -0.025518 1.005225 -0.792409 ... ... ... ... ... 2002-09-22 -0.827884 0.614906 -0.871884 1.219365 2002-09-23 0.083260 0.468676 -0.803836 0.798946 2002-09-24 0.908064 -0.526946 0.538067 0.067274 2002-09-25 1.715925 -1.253660 -0.327901 -2.050811 2002-09-26 -0.224802 0.335902 -1.158583 -0.413148 [1000 rows x 4 columns] """ print() dataFrame2 = pd.read_excel("test.xlsx", "Sheet1", index_col = None, na_values = ["NA"]) print(dataFrame2) """ Unnamed: 0 A B C D 0 2000-01-01 0.053874 0.285479 2.200199 -0.497760 1 2000-01-02 0.382564 0.032303 2.176588 0.970032 2 2000-01-03 -0.960918 0.380824 -0.187437 -0.691698 3 2000-01-04 -0.854058 -1.280247 -1.469207 -1.037654 4 2000-01-05 0.141451 -0.025518 1.005225 -0.792409 .. ... ... ... ... ... 995 2002-09-22 -0.827884 0.614906 -0.871884 1.219365 996 2002-09-23 0.083260 0.468676 -0.803836 0.798946 997 2002-09-24 0.908064 -0.526946 0.538067 0.067274 998 2002-09-25 1.715925 -1.253660 -0.327901 -2.050811 999 2002-09-26 -0.224802 0.335902 -1.158583 -0.413148 [1000 rows x 5 columns] """ |
▶ requirements.txt
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
defusedxml==0.7.1 et_xmlfile==2.0.0 numpy==2.1.3 odfpy==1.4.1 openpyxl==3.1.5 packaging==24.2 pandas==2.2.3 python-calamine==0.3.1 python-dateutil==2.9.0.post0 pytz==2024.2 pyxlsb==1.0.10 six==1.16.0 tzdata==2024.2 xlrd==2.0.1 XlsxWriter==3.2.0 |
※ pip install "pandas[excel]" 명령을 실행했다.