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")



39 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
    Replies
    1. In Python, using the Pandas library, you can efficiently find the largest and smallest rows in a DataFrame based on one or more columns.
      python projects for engineering students
      Largest and Smallest Rows Based on a Single Column
      To find the rows with the largest and smallest values in a specific column, use the idxmax() and idxmin() methods, which return the index of the maximum and minimum values, respectively.
      Machine Learning Final Year Projects
      Largest and Smallest Rows Based on Multiple Columns
      If you want to find the largest and smallest rows based on multiple columns, you can use the loc method combined with idxmax() and idxmin() for multiple columns.
      Deep Learning Projects for Final Year

      Delete
  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
  20. What a wonderful read! Your writing style is engaging, and the information you provide is incredibly valuable. Thank you for sharing your expertise with us!

    Data science courses in Gujarat

    ReplyDelete
  21. Awesome insights on finding the largest and smallest rows in a Pandas DataFrame! Your clear examples make it easier for learners to grasp these concepts. Keep sharing your knowledge; it’s helping many to level up their data manipulation skills!
    Data Science Courses in Singapore

    ReplyDelete
  22. "This post is a must-read for anyone interested in data science! The data science courses in Faridabad provide a solid foundation and practical skills."

    ReplyDelete
  23. Great insights on the data science courses available! I appreciate the detailed descriptions and recommendations. I’ll be checking out these data science courses in Faridabad soon. Thanks for the valuable information!

    ReplyDelete
  24. Great example! Simple and practical way to use Pandas for finding top and bottom values. The clear explanation and real data use case make it easy to follow. Thanks for sharing
    data analytics courses in dubai

    ReplyDelete
  25. Great insights on handling dataframes in Python! Your exploration of finding the largest and smallest rows in Pandas is not only practical but also essential for data analysis. Keep sharing these valuable tips; they truly help demystify data manipulation for many!
    Data Science Courses in Singapore

    ReplyDelete
  26. This post provides a clear and helpful explanation of finding the largest and smallest values in a Pandas DataFrame. The examples are straightforward and practical, making it easy for readers to apply the concepts to their own datasets. Thanks for sharing such useful insights into data manipulation with Python!
    Data science courses in Bhutan

    ReplyDelete
  27. Your blog on how identify largest or smallest n rows with example is very nice. As the example provided makes it make to understand. Very insightful blog.
    Online Data Science Course

    ReplyDelete
  28. The way you explained the topic made it so easy to understand. I appreciate the examples you included; they added a lot of depth. Looking forward to reading more of largest and smallest rows is very helpful. Great job.
    Online Data Science Course




    ReplyDelete
  29. AI Data Science Biz delivers a clear and practical guide on working with Python Pandas DataFrames, focusing on identifying the largest and smallest values. The explanations are concise and easy to follow, making it a valuable resource for data scientists and Python enthusiasts alike.
    data analytics courses in dubai

    ReplyDelete
  30. Thanks for the informative post on using Pandas DataFrames! Your examples of finding the largest and smallest values are super helpful for anyone working with data in Python. Keep up the great work!
    Data science courses in Bhutan

    ReplyDelete
  31. it is 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 science courses in Visakhapatnam

    ReplyDelete