Python函数的Python进度条
我想添加一个进度条,显示执行函数的进度。该函数从postgresql数据集导入数据,最后绘制每个段百分比的条形图 这是我的密码:Python函数的Python进度条,python,progress-bar,Python,Progress Bar,我想添加一个进度条,显示执行函数的进度。该函数从postgresql数据集导入数据,最后绘制每个段百分比的条形图 这是我的密码: class RfmTable: def __init__(self,table_name,start_date,end_date): self.table_name = table_name self.start_date = start_date self.end_date = end_date self.quintiles = {
class RfmTable:
def __init__(self,table_name,start_date,end_date):
self.table_name = table_name
self.start_date = start_date
self.end_date = end_date
self.quintiles = {}
def rfm_chart(self):
conn = psycopg2.connect(database=database_name, user=user_name,
password=password_info, host=host_info, port=port_info)
cursor = conn.cursor()
cursor.execute(...) #table information
a = cursor.fetchall()
# rfm analysis
# draw the chart
for i, bar in enumerate(bars):
value = bar.get_width()
if segments_counts.index[i] in ['重要价值用户']:
bar.set_color('firebrick')
ax.text(value,
bar.get_y() + bar.get_height()/2,
'{:,} ({:}%)'.format(int(value),
int(value*100/segments_counts.sum())),
va='center',
ha='left'
)
return plt.show()
那么,向函数中添加进度条的好方法是什么呢 进度条可能是python最具特色的进度条。您只需使用pip install tqdm
即可安装它
下面的代码演示了它的易用性
from tqdm import tqdm
import time
for i in tqdm(range(100)):
time.sleep(0.1)
这是在pycharm中运行上述代码示例后的样子:
1:完成百分比2:进度条
3:总迭代中的当前迭代
4:经过的时间
5:预计剩余时间
6:每秒处理的迭代次数进度条可能是python最具特色的进度条。您只需使用
pip install tqdm
即可安装它
下面的代码演示了它的易用性
from tqdm import tqdm
import time
for i in tqdm(range(100)):
time.sleep(0.1)
这是在pycharm中运行上述代码示例后的样子:
1:完成百分比2:进度条
3:总迭代中的当前迭代
4:经过的时间
5:预计剩余时间
6:每秒处理的迭代次数