Skip to content

Commit

Permalink
show status when running Pandas apply
Browse files Browse the repository at this point in the history
  • Loading branch information
crosenth committed Dec 29, 2015
1 parent 1ba7d55 commit 3ea3efc
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions bioy_pkg/utils.py
Expand Up @@ -32,6 +32,22 @@
log = logging.getLogger(__name__)


def apply_df_status(func, df, msg=''):
"""
"""
tmp_column = 'index_number'
row_count = float(len(df))
df[tmp_column] = xrange(int(row_count))
msg += ' {:.0%}\r'

def apply_func(item, msg):
sys.stderr.write(msg.format(item[tmp_column] / row_count))
return func(item)

df = df.apply(apply_func, args=[msg], axis=1)
return df.drop(tmp_column, axis=1)


def flattener(iterable):
"""
Flatten nested iterables (not strings or dict-like objects).
Expand Down

0 comments on commit 3ea3efc

Please sign in to comment.