-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexcel_read_comparison.py
49 lines (32 loc) · 1.58 KB
/
excel_read_comparison.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
import os
import time
import pandas as pd
import openpyxl
from excel_utils import ExcelRead, ExcelWrite, ExcelReadT, ExcelWriteT
PROJECT_PATH = os.path.abspath(os.path.dirname(__file__))
excel_file_name = PROJECT_PATH + '/' + 'file_example_XLSX_5000.xlsx'
excel_output_file_name = PROJECT_PATH + '/' + 'file_example_XLSX_5000_output.xlsx'
start_time = time.time()
excelreadrow = ExcelRead() # read by rows
data = excelreadrow.openpyxl_read_excel(excel_file_name)
excelrowwrite = ExcelWrite();
if os.path.isfile(excel_output_file_name) != True:
excelrowwrite.openpyxl_write_new_excel_file(excel_output_file_name)
excelrowwrite.openpyxl_write_existing_excel_file(excel_output_file_name, data)
end_time = time.time()
print('Reading and writing a excel by row with openpyxl library:\t' + (str)(end_time - start_time) + 's.')
start_time = time.time()
excelreadcol = ExcelReadT() # read by columns
data = excelreadcol.openpyxl_read_excel(excel_file_name)
excelcolwrite = ExcelWriteT();
if os.path.isfile(excel_output_file_name) != True:
excelcolwrite.openpyxl_write_new_excel_file(excel_output_file_name)
excelcolwrite.openpyxl_write_existing_excel_file(excel_output_file_name, data)
end_time = time.time()
print('Reading and writing a excel by column with openpyxl library:\t' + (str)(end_time - start_time) + 's.')
start_time = time.time()
data = pd.read_excel(excel_file_name, index_col=0, engine="openpyxl")
df = pd.DataFrame(data)
df.to_excel(excel_output_file_name)
end_time = time.time()
print('Reading and writing a excel with pandas (openpyxl engine):\t' + (str)(end_time - start_time) + 's.')