Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
The Pandas Workshop

You're reading from   The Pandas Workshop A comprehensive guide to using Python for data analysis with real-world case studies

Arrow left icon
Product type Paperback
Published in Jun 2022
Publisher Packt
ISBN-13 9781800208933
Length 744 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Authors (4):
Arrow left icon
Blaine Bateman Blaine Bateman
Author Profile Icon Blaine Bateman
Blaine Bateman
William So William So
Author Profile Icon William So
William So
Saikat Basak Saikat Basak
Author Profile Icon Saikat Basak
Saikat Basak
Thomas Joseph Thomas Joseph
Author Profile Icon Thomas Joseph
Thomas Joseph
Arrow right icon
View More author details
Toc

Table of Contents (21) Chapters Close

Preface 1. Part 1 – Introduction to pandas
2. Chapter 1: Introduction to pandas FREE CHAPTER 3. Chapter 2: Working with Data Structures 4. Chapter 3: Data I/O 5. Chapter 4: Pandas Data Types 6. Part 2 – Working with Data
7. Chapter 5: Data Selection – DataFrames 8. Chapter 6: Data Selection – Series 9. Chapter 7: Data Exploration and Transformation 10. Chapter 8: Understanding Data Visualization 11. Part 3 – Data Modeling
12. Chapter 9: Data Modeling – Preprocessing 13. Chapter 10: Data Modeling – Modeling Basics 14. Chapter 11: Data Modeling – Regression Modeling 15. Part 4 – Additional Use Cases for pandas
16. Chapter 12: Using Time in pandas 17. Chapter 13: Exploring Time Series 18. Chapter 14: Applying pandas Data Processing for Case Studies 19. Chapter 15: Appendix 20. Other Books You May Enjoy

Solution 6.1

In this activity, you will read in some US population data for large cities for the years 2010 and 2019 and perform some analysis:

  1. For this activity, all you will need is the pandas library. Load it in the first cell of the notebook:
    import pandas as pd
  2. Read a pandas Series from the US_Census_SUB-IP-EST2019-ANNRNK_top_20_2010.csv file. The city names are in the first column; read them in such that they are used as the index. List out the resulting Series:
    populations_2010 = \
    pd.read_csv('..//Datasets//US_Census_SUB-IP-EST2019-ANNRNK_top_20_2010.csv',
                index_col = [0],
                squeeze = True) 
    populations_2010

The result should be as follows:

Figure 15.18 – Populations_2010 Series

Note that in addition to specifying index_col = [1], we use squeeze = True to store the result in a...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €18.99/month. Cancel anytime