TQDM从.xlsx表的每行一个进度栏
我编写了一个脚本,该脚本从Excel表上读取并执行了每行的数据操作。我想看到一个进度栏,显示了操作的全部进度。如您在图像中看到的那样,每行之后显示进度条。
这是代码。
print('Reading Rows...')
for row in tqdm(range(2, sheet.max_row + 1)):
# Each row in the spreadsheet has data for one census tract
state = sheet['B' + str(row)].value
county = sheet['C' + str(row)].value
pop = sheet['D' + str(row)].value
# ToDo: Open a new text file and write the content of countyData to it
countyData.setdefault(state, {})
#Make sure the key for this county in this state exists.
countyData[state].setdefault(county, {'tracts':0, 'pop':0})
# Each row represnts one census tract, so increment by one
countyData[state][county]['tracts'] += 1
countyData[state][county]['pop'] += 1
#Todo: Open a new file and write the contents of countyData to it.
print('Writing results...')
resultFile = open('census2010.py', 'w')
resultFile.write('allData = ' + pprint.pformat(countyData))
resultFile.close()
print('Done')
I wrote a script that reads and performs some data manipulation on each row from Excel Sheet. I want to see a progress bar that shows the whole progress of the operation. As you can see in the image, the progress bar is shown after every row.
Here is the code.
print('Reading Rows...')
for row in tqdm(range(2, sheet.max_row + 1)):
# Each row in the spreadsheet has data for one census tract
state = sheet['B' + str(row)].value
county = sheet['C' + str(row)].value
pop = sheet['D' + str(row)].value
# ToDo: Open a new text file and write the content of countyData to it
countyData.setdefault(state, {})
#Make sure the key for this county in this state exists.
countyData[state].setdefault(county, {'tracts':0, 'pop':0})
# Each row represnts one census tract, so increment by one
countyData[state][county]['tracts'] += 1
countyData[state][county]['pop'] += 1
#Todo: Open a new file and write the contents of countyData to it.
print('Writing results...')
resultFile = open('census2010.py', 'w')
resultFile.write('allData = ' + pprint.pformat(countyData))
resultFile.close()
print('Done')
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以删除此行
,看看它是否仍然显示出这种方式,可能会引起打印语句。
例如,查看以下代码
在Hello消息后将显示新的进度栏,并删除打印语句解决了它。
Could you remove this line
and see if it still shows that way , probably the print statement causes it.
For example look at the following code
A new progress bar will be shown after the hello message , and removing the print statement solves it.