Discover more from Daily Dose of Data Science
Supercharge value_counts() Method in Pandas With Sidetable
The 𝐯𝐚𝐥𝐮𝐞_𝐜𝐨𝐮𝐧𝐭𝐬() method is commonly used to analyze categorical columns, but it has many limitations.
For instance, if one wants to view the percentage, cumulative count, etc., in one place, things do get a bit tedious. This requires more code and is time-consuming.
Instead, use 𝐬𝐢𝐝𝐞𝐭𝐚𝐛𝐥𝐞. Consider it as a supercharged version of 𝐯𝐚𝐥𝐮𝐞_𝐜𝐨𝐮𝐧𝐭𝐬(). As shown below, the 𝐟𝐫𝐞𝐪() method from sidetable provides a more useful summary than 𝐯𝐚𝐥𝐮𝐞_𝐜𝐨𝐮𝐧𝐭𝐬().
Additionally, sidetable can aggregate multiple columns too. You can also provide threshold points to merge data into a single bucket. What's more, it can print missing data stats, pretty print values, etc.
Read more: GitHub.
Share this post on LinkedIn: Post Link.
Thanks for reading Daily Dose of Data Science! Subscribe for free to learn something new and insightful about Python and Data Science every day. Also, get a Free Data Science PDF (250+ pages) with 200+ tips.