【发布时间】:2020-11-05 10:30:47
【问题描述】:
正如标题所示,我正在尝试在执行pandas.to_csv 时显示进度条。
我有以下脚本:
def filter_pileup(pileup, output, lists):
tqdm.pandas(desc='Reading, filtering, exporting', bar_format=BAR_DEFAULT_VIEW)
# Reading files
pileup_df = pd.read_csv(pileup, '\t', header=None).progress_apply(lambda x: x)
lists_df = pd.read_csv(lists, '\t', header=None).progress_apply(lambda x: x)
# Filtering pileup
intersection = pd.merge(pileup_df, lists_df, on=[0, 1]).progress_apply(lambda x: x)
intersection.columns = [i for i in range(len(intersection.columns))]
intersection = intersection.loc[:, 0:5]
# Exporting filtered pileup
intersection.to_csv(output, header=None, index=None, sep='\t')
在前几行我找到了一种集成进度条的方法,但这种方法不适用于最后一行,我该如何实现?
【问题讨论】:
-
以一种非常 hacky 的方式,您可以创建一个从
io.TextIOBase周围的output继承的包装类,该类将.write调用传递给output,同时更新进度条。不过不推荐,所以我不会将其发布为答案。 -
您找到解决方案了吗?如果您能将其发布为答案,我将不胜感激:)
-
@Sierox 我还没有找到解决这个确切问题的方法,但最终,我使用了 dask 模块,而不是 pandas,该模块本身在
dask.diagnostics下有一个进度条@