TQDM从.xlsx表的每行一个进度栏

发布于 2025-01-21 11:09:24 字数 1190 浏览 2 评论 0原文

我编写了一个脚本,该脚本从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.

snapshot:
enter image description here

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

如果没有 2025-01-28 11:09:24

您可以删除此行

print('Writing results...')

,看看它是否仍然显示出这种方式,可能会引起打印语句。

例如,查看以下代码

for i in tqdm(range(int(9e6))):
    if(i%10000==0):
        print("hello")
    pass

在Hello消息后将显示新的进度栏,并删除打印语句解决了它。

Could you remove this line

print('Writing results...')

and see if it still shows that way , probably the print statement causes it.

For example look at the following code

for i in tqdm(range(int(9e6))):
    if(i%10000==0):
        print("hello")
    pass

A new progress bar will be shown after the hello message , and removing the print statement solves it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文