From bc1a59dce7a07c9825b8c178b31ec2857731fba2 Mon Sep 17 00:00:00 2001 From: gusgordon Date: Sat, 11 Feb 2017 17:40:23 +0000 Subject: [PATCH] BUG: Replace zeros with NaNs before counting --- pyfolio/plotting.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyfolio/plotting.py b/pyfolio/plotting.py index 3471e7c7..f7131315 100644 --- a/pyfolio/plotting.py +++ b/pyfolio/plotting.py @@ -349,7 +349,7 @@ def plot_holdings(returns, positions, legend_loc='best', ax=None, **kwargs): ax = plt.gca() positions = positions.copy().drop('cash', axis='columns') - df_holdings = positions.apply(lambda x: np.sum(x != 0), axis='columns') + df_holdings = positions.replace(0, np.nan).count(axis=1) df_holdings_by_month = df_holdings.resample('1M').mean() df_holdings.plot(color='steelblue', alpha=0.6, lw=0.5, ax=ax, **kwargs) df_holdings_by_month.plot(