Dav*_*cco 6 python pandas visual-studio-code jupyter-notebook
当我progress_apply在 MS Visual Studio Code 中对 Pandas 数据帧执行“矢量”操作时,我试图显示一个进度条。
在启用了Python 扩展的VS Code 中,我在一个单元格中尝试过
import pandas as pd
from tqdm import tqdm_notebook, tqdm_pandas
tqdm_notebook().pandas()
df = pd.DataFrame({'a' : ['foo', 'bar'], 'b' : ['spam', 'eggs']})
df.progress_apply(lambda row: row['a'] + row['b'], axis = 1)
Run Code Online (Sandbox Code Playgroud)
结果是
并且不呈现进度条。我想要一个进度条来渲染有点像它发生的
from tqdm import tqdm
for i in tqdm(range(len(df))):
pass
Run Code Online (Sandbox Code Playgroud)
我很困惑,因为上面的语法在 Firefox 上的“经典”Jupyter 笔记本中运行良好
progress_apply在 vscode 中运行Pandas时如何可视化进度条?
在 2022 年重新审视这一点(VS Code 1.63.2),下面的代码将在 VS Code 中正常工作,并且可能比我之前为此使用的其他解决方案在视觉上更具吸引力:
import pandas as pd
from tqdm.notebook import tqdm
tqdm.pandas()
df = pd.DataFrame({'a' : ['foo', 'bar'], 'b' : ['spam', 'eggs']})
df.progress_apply(lambda row: row['a'] + row['b'], axis = 1)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3421 次 |
| 最近记录: |