Monday, April 17, 2017

Python Pandas Dataframe - Largest and Smallest Rows

Here is an example on how identify largest or smallest n rows.
Source Data : Census data for state of California.

Use Case : 
Read Population data for state of California from "censusdata.ire.org".
Get 3 Counties with highest population.
Get 3 Counties with lowest population.


Syntax : 


  DataFrame.nlargest()
  DataFrame.nsmallest()


Main Parameters :


  • Number of Items to retrieve
  • Columns to sort on
  • Rows to keep in case of duplicates ( keep=first or keep=last )


Sample Code


Read Source Data and select subset of columns.
County name and Population selected.

import pandas as pd
df = pd.read_csv("http://censusdata.ire.org/06/all_050_in_06.P1.csv")
df = df[["NAME","POP100"]]
df












Select Top 3 counties with highest population
df.nlargest(3,"POP100")












Select 3 counties with lowest population
df.nsmallest(3,"POP100")



23 comments:

  1. Not at all like an information investigator who examines information from a restricted arrangement of sources, an information researchers sources information from various different sources.data science course in pune

    ReplyDelete
  2. I feel very grateful that I read this. It is very helpful and very informative and I really learned a lot from it.
    business analytics course in delhi

    ReplyDelete
  3. Attend The Machine Learning course in Bangalore From ExcelR. Practical Machine Learning course in Bangalore Sessions With Assured Placement Support From Experienced Faculty. ExcelR Offers The Machine Learning course in Bangalore.
    Machine Learning course in Bangalore

    ReplyDelete

  4. Excelr is providing emerging & trending technology training, such as for data science, Machine learning, Artificial Intelligence, AWS, Tableau, Digital Marketing. Excelr is standing as a leader in providing quality training on top demanding technologies in 2019. Excelr`s versatile training is making a huge difference all across the globe. Enable ?business analytics? skills in you, and the trainers who were delivering training on these are industry stalwarts. Get certification on "
    data science course fees in hyderabad"
    and get trained with Excelr.

    ReplyDelete
  5. Excellent Blog! I would like to thank for the efforts you have made in writing this post. I am hoping the same best work from you in the future as well. I wanted to thank you for this websites! Thanks for sharing. Great websites!
    data analytics courses

    ReplyDelete
  6. I need to to thank you for this very good read!! I definitely loved every little bit of it. I have you bookmarked to check out new things you post… data science course bangalore

    ReplyDelete
  7. I have to search sites with relevant information on given topic and provide them to teacher our opinion and the article.

    Dental care for kids

    ReplyDelete
  8. Regular visits listed here are the easiest method to appreciate your energy, which is why why I am going to the website everyday, searching for new, interesting info. Many, thank you!

    data science course
    360DigiTMG

    ReplyDelete
  9. Great post i must say and thanks for the information. Education is definitely a sticky subject. However, is still among the leading topics of our time. I appreciate your post and look forward to more.

    data analytics courses

    business analytics course

    data science interview questions

    data science course in mumbai

    ReplyDelete
  10. Such a very useful article. Very interesting to read this article.I would like to thank you for the efforts you had made for writing this awesome article. data scientist courses

    ReplyDelete
  11. The word artificial Intelligence was coined by John McCarthy in 1956 at Dartmouth College data science course in india

    ReplyDelete
  12. After this brings up its clients get entertained well with its premium services, the Aerocity Russian Escorts is liable to increase the level of fun by its quality services dissimilar to get anywhere. So, let us forget everything and take pleasure in what you wait for a long time. Check our other Services...
    Aerocity Russian Escorts
    Aerocity Russian Escorts
    Aerocity Russian Escorts
    Agra Escorts Service Agency
    Agra Escorts Service Agency
    Agra Escorts Service Agency
    Agra Escorts Service Agency

    ReplyDelete
  13. Thanks for sharing the information. It’s really helpful to those who are planning to learn Data Science

    Data Science Training in Hyderabad

    ReplyDelete
  14. Amazing blog extremely good, i enjoyed with the incredible informative.

    Data Science Training in Pune

    ReplyDelete
  15. Wonderful blog post. This is absolute magic from you! I have never seen a more wonderful post than this one. You've really made my day today with this. I hope you keep this up!
    data analytics training in hyderabad

    ReplyDelete
  16. Great post I would like to thank you for the efforts you have made in writing this interesting and knowledgeable article. data scientist course in kanpur

    ReplyDelete
  17. I really loved reading your blog. It was very well authored and easy to understand. Unlike other blogs I have read which are really not that good.Thanks alot! data science course in mysore

    ReplyDelete
  18. I have read your article; it is very informative and helpful for me. I admire the valuable information you offer in your articles. Thanks for posting it. data science course in surat

    ReplyDelete
  19. Excellent Blog! I would like to thank for the efforts you have made in writing this post.Are you trying to find the perfect institute for an advanced ac mechanic course in Delhi that will provide you with everything you need? You arrived at the proper location. ABCTech institute in Delhi have you covered.

    ReplyDelete