Skip to content

Pandas progress bar when iterating over rows #322

@Aorus42

Description

@Aorus42

Maybe this is already taken care of and I just don't know how to use the pandas implementation correctly, but the tqdm progress bar returns an incorrect total when running apply(axis=1), i.e. applying a function to each row of a dataframe. I have implemented the following fix for myself, but could something similar be added to the official code? Thanks!

# Precompute total iterations
if kwargs.get('axis', 0) == 1:
    total = len(df)
else:
    total = getattr(df, 'ngroups', None)
    if total is None:  # not grouped
        total = len(df) if isinstance(df, Series) \
            else df.size // len(df)
    else:
        total += 1  # pandas calls update once too many

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions