When You Should Not Use the head() Method In Pandas
One often retrieves the top ๐ค rows of a sorted Pandas DataFrame by using ๐ก๐๐๐() method. However, there's a flaw in this approach.
If your data has repeated values, ๐ก๐๐๐() will not consider that and just return the first ๐ค rows.
If you want to consider repeated values, use ๐ง๐ฅ๐๐ซ๐ ๐๐ฌ๐ญ (or ๐ง๐ฌ๐ฆ๐๐ฅ๐ฅ๐๐ฌ๐ญ) instead. Here, you can specify the desired behavior for duplicate values using the ๐ค๐๐๐ฉ parameter.
Share this post on LinkedIn: link.
Find the code for my tips here:ย GitHub.
I like to explore, experiment and write about data science concepts and tools. You can read my articles on Medium. Also, you can connect with me on LinkedIn.


