如何在 Jupyter 中为 Pandas 修复 tqdm progress_apply?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/45595689/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to fix tqdm progress_apply for pandas in Jupyter?
提问by sortas
Don't really understand is it a mistake or just my local problem, still have some issues with using tqdm progress barswith progress_applyin Jupyter.
真的不明白它是一个错误或者只是我的局部问题,还有使用一些问题tqdm进度条与progress_apply在Jupyter。
First try:
第一次尝试:
from tqdm import tqdm
tqdm_notebook.pandas(desc="Example Desc")
keywords_df['keyword'] = keywords_df['keywird'].progress_apply(lambda x: x.replace('*',''))
Output(without any bars):
输出(没有任何条):
AttributeError: 'function' object has no attribute 'pandas'
Second try:
第二次尝试:
from tqdm import tqdm
tqdm_notebook().pandas(desc="Example Desc")
keywords_df['keyword'] = keywords_df['keywird'].progress_apply(lambda x: x.replace('*',''))
Output:Two bars (need one). First bar is empty (0it [00:00, ?it/s]), second is OK.
输出:两根棒(需要一根)。第一个栏是空的(0it [00:00, ?it/s]),第二个是好的。
Any ideas how to change progress_applydescription and display bar without empty initialization bar? :)
任何想法如何在没有空初始化栏的情况下更改progress_apply描述和显示栏?:)
P.S.Documentation (https://github.com/tqdm/tqdm) says I can just use tqdm_notebook, but it's not working for me :)
PS文档(https://github.com/tqdm/tqdm)说我只能使用tqdm_notebook,但它对我不起作用:)
# Register `pandas.progress_apply` and `pandas.Series.map_apply` with `tqdm`
# (can use `tqdm_gui`, `tqdm_notebook`, optional kwargs, etc.)
tqdm.pandas(desc="my bar!")
回答by sortas
回答by DJK
Assuming your question is about how to use the status bar, vs the ascetics of the status bar on the Jupyter NoteBook then your code should be
假设您的问题是关于如何使用状态栏,而不是 Jupyter NoteBook 上状态栏的苦行者,那么您的代码应该是
tqdm.pandas(desc="Example Desc")
keywords_df['keyword'] = keywords_df['keywird'].progress_apply(lambda x: x.replace('*',''))
回答by Nic Scozzaro
This is what I run in my jupyter notebooks, and then progress_apply works:
这是我在 jupyter 笔记本中运行的内容,然后 progress_apply 起作用:
from tqdm import tqdm, tqdm_notebook
tqdm_notebook().pandas()
I had been getting an error without the () after tqdm_notebook
在 tqdm_notebook 之后没有 () 时出现错误
回答by nag
The following is working for me:
以下对我有用:
from tqdm import tqdm
tqdm.pandas()
keywords_df['keyword'] = keywords_df['keywird'].progress_apply(lambda x: x.replace('*',''))
回答by Onno Eberhard
Now you can just do:
现在你可以这样做:
from tqdm.notebook import tqdm
tqdm.pandas()
df.progress_apply(...)
My version of tqdm is 4.39.0
我的tqdm版本是4.39.0