From d2d19d18283364bfe5a270d202f7866263fd14af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hasan=20Alper=20Ayd=C4=B1n?= Date: Thu, 22 Sep 2022 20:49:11 +0300 Subject: [PATCH] improve stats summary in cat_plot --- src/klib/describe.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/klib/describe.py b/src/klib/describe.py index 5b1560f..8d95d6b 100644 --- a/src/klib/describe.py +++ b/src/klib/describe.py @@ -92,15 +92,16 @@ def cat_plot( lim_top, lim_bot = top, bottom if n_unique < top + bottom: - lim_top = int(n_unique // 2) - lim_bot = int(n_unique // 2) + 1 - - if n_unique <= 2: - lim_top = lim_bot = int(n_unique // 2) - + if bottom > top: + lim_top = int(n_unique // 2) if int(n_unique // 2) < top else top + lim_bot = n_unique - lim_top + else: + lim_bot = int(n_unique // 2) if int(n_unique // 2) < bottom else bottom + lim_top = n_unique - lim_bot + value_counts_top = value_counts[:lim_top] value_counts_idx_top = value_counts_top.index.tolist() - value_counts_bot = value_counts[-lim_bot:] + value_counts_bot = value_counts[-lim_bot:] if lim_bot > 0 else pd.DataFrame() value_counts_idx_bot = value_counts_bot.index.tolist() if top == 0: