Мне нужно добавить индикатор выполнения в моем скрипте Python, чтобы указать оставшееся время до выполнения скрипта.
это оригинальный код:
import pandas as pd
import xlsxwriter
import sys
import os
""" Enter the directory of the exported csv file"""
user_input = input("Enter the path of your file: ")
assert os.path.exists(user_input), "I did not find the file at, "+str(user_input)
f = open(user_input,'r+')
print("We found your file!")
"""Organize the exported file """
inputFile = f
workbook = xlsxwriter.Workbook('output01.xlsx')
worksheet = workbook.add_worksheet()
exportFile = open('output01.xlsx', 'w')
workbook.close()
for line in inputFile:
new_line = line.replace(',', '\t')
exportFile.write(new_line)
f.close()
inputFile.close()
exportFile.close()
df = pd.read_table('output01.xlsx', error_bad_lines=False) # for '\t'
df.to_excel('output1.xlsx', 'Sheet1')
"""Count the number of duplicates """
data = pd.read_excel(r'output1.xlsx', header = 0)
data.count()
data['count'] = data.groupby(['Payload'])['Index'].transform('count')
data.to_excel('OutputDLT.xlsx', sheet_name='sheet1', index=False)
print("Conversion is done!")
это мой код после использования библиотеки tqdm
import pandas as pd
import xlsxwriter
import sys
import os
from tqdm import tqdm
import time
for i in range(100):
output = tqdm.tqdm(total=50, desc='Conversion', position=0)
""" Enter the directory of the exported csv file"""
user_input = input("Enter the path of your file: ")
assert os.path.exists(user_input), "I did not find the file at, "+str(user_input)
f = open(user_input,'r+')
print("We found your file!")
"""Organize the exported file """
for j in range(50):
inputFile = f
workbook = xlsxwriter.Workbook('output01.xlsx')
worksheet = workbook.add_worksheet()
exportFile = open('output01.xlsx', 'w')
workbook.close()
for line in inputFile:
new_line = line.replace(',', '\t')
exportFile.write(new_line)
f.close()
inputFile.close()
exportFile.close()
df = pd.read_table('output01.xlsx', error_bad_lines=False) # for '\t'
df.to_excel('output1.xlsx', 'Sheet1')
"""Count the number of duplicates """
data = pd.read_excel(r'output1.xlsx', header = 0)
data.count()
data['count'] = data.groupby(['Payload'])['Index'].transform('count')
data.to_excel('OutputDLT.xlsx', sheet_name='sheet1', index=False)
print("Conversion is done!")
output.update(1)
это вывод на консоль:
Conversion: 0%| | 0/50 [00:00<?, ?it/s]
Enter the path of your file: C:/Users/khouloud.ayari/Desktop/PSA/PSA/khouloud/export dlt file from dlt viewer/21-11-2.csv
We found your file!
Conversion is done!
Conversion: 2%|▏ | 1/50 [01:21<1:06:14, 81.12s/it]Traceback (most recent call last):
это ошибка:
for line in inputFile:
ValueError: I/O operation on closed file.
Я не знаю, почему файл закрыт и выполнение сценария прерывается.