How to Learn Pandas for Data Analysis by Solving Projects

598.0K views
•
June 21, 2023
by
freeCodeCamp.org
YouTube video player
How to Learn Pandas for Data Analysis by Solving Projects

TL;DR

Watching tutorials alone will not make you a data analyst; you have to solve real projects, which is why this course teaches pandas through hands-on projects instead of lectures. It covers data analysis, data cleaning, and data wrangling, starting with an English-words DataFrame of 172,821 entries and growing in complexity through Pokemon filtering and the NBA Birthday Paradox.

Transcript

Learn how to use pandas for data analysis and data science in this full course for beginners. You will learn pandas by example from Santiago. He is an experienced developer and he also created one of the most popular data analysis courses on the internet. So you are in good hands. Let's get started. Hello, my name is Santiago and this is pandas by ... Read More

Key Insights

  • Practicing beats passive watching in data science, the same way playing football beats watching it on TV. Santiago frames the entire course around this: just watching videos does not make you an expert, so each chapter is a project to solve rather than a lecture to absorb.
  • DataWars is a platform focused entirely on practicing data science with real-life projects broken into bite-size activities that can be checked at each stage of the process. It contains no videos, only projects, and it is entirely free to sign up.
  • The English-words DataFrame uses the word itself as the index rather than a numeric position, which is why understanding index selection matters. Any word can then be retrieved directly by passing it to .loc, making the index the primary access path into the data.
  • The value column is computed by adding up the individual values of each character, where A is 1, B is 2, C is 3, and so on. The char count column is simply the length of the word, so both columns are numeric and appear in summary statistics.
  • df.info() reports the index range and the total entry count, showing 172,821 words in this dataset. df.shape returns the same count as the dimensions of the DataFrame matrix, so either method answers how many elements the data contains.
  • Row selection with .loc returns a series, not a row-shaped object. The horizontal row structure is projected into a vertical series structure, which is a transposing behavior worth recognizing when a single-row selection looks unexpectedly stacked.
  • df.loc accepts two parameters: the index selection first, then the columns. Passing the column name avoids scrolling through a wide DataFrame, so on a table with 100 columns you can request just the value you need instead of browsing for it.
  • df.loc also accepts a list of index values, not just a single one, which enables multi-selection of several rows at once. Combining a list of words with a column name returns just that column's value for each selected row.
  • df.describe() returns summary statistics for all numeric columns, including average, minimum, and maximum. In the English-words dataset the maximum value is 319 and the maximum char count is 28, so describe answers several activities at once.

Install to Summarize YouTube Videos and Get Transcripts

Explore YouTube Video Summarizer or Get YouTube Transcript Extractor

Questions & Answers

Q: How do I learn pandas effectively as a beginner?

Santiago's argument is that you learn pandas by solving projects, not by watching videos. He compares it to football: you do not get better at playing football just by watching games on TV, you have to go out and practice. The same applies to data science or any other analytical discipline. This course is structured so each chapter is a real project, and viewers are explicitly encouraged to pause the video before each activity and try to resolve it themselves before the solution is revealed.

Q: What is DataWars and is it free?

DataWars is a platform 100% focused on practicing data science and applying your skills with real-life projects. It contains no videos at all, just projects to resolve, broken into bite-size activities that you can check at each stage of the process. It is entirely free. The list of all the projects covered in this course, plus sign-up instructions, is available at datawars.io/freecodecamp. The course itself was created by Santiago Basulto from DataWars as a collaboration with freeCodeCamp.

Q: How do I find out how many rows a pandas DataFrame has?

There are multiple ways. The most common is the info method, which prints an understanding of the index, showing the range of entries from the first to the last, along with the total number of entries. In the English-words dataset, info reports 172,821 words. The alternative is the shape attribute, which gives the shape of the matrix that makes up the DataFrame and returns the same count. Both answer the question, so pick whichever is more convenient.

Q: How does .loc work for selecting rows in pandas?

The .loc method does index selection, so you pass whatever value you want for an index and it returns that row. In the English-words dataset the index is the word itself, so you can retrieve any word directly by passing it to .loc. The result comes back as a series rather than a row, meaning the horizontal row structure is projected into a vertical structure. It is a transposing behavior worth recognizing, but not something to over-think.

Q: How do I select a specific column value with .loc in pandas?

df.loc accepts two parameters: the index selection first, then the columns. Instead of returning the entire row and scrolling to find what you need, you pass the column name as the second argument and get just that value back. Santiago points out the practical reason: imagine a DataFrame with 100 columns. It would be very hard to browse and scroll to the value you are looking for, so specifying the column directly is far more convenient.

Q: Can I select multiple rows at once with .loc?

Yes. Selection in pandas with df.loc takes potentially a list of index values to retrieve, not just one. Instead of passing a single word, you pass each one of them in a list and get all those rows back as a multi-selection. You can also combine this with the second parameter, so passing a list of words plus a column name such as value returns just that column's value for each of the selected rows rather than the full rows.

Q: What does df.describe() show in pandas?

The describe method gives you summary statistics of all your numeric columns. In the English-words dataset both columns are numeric, so both are covered. It reports the average value, the average char count, the minimum value, the maximum value for character count, the maximum value for value, and other summary statistics. This makes it an efficient way to answer several questions at once, such as the highest possible value of a word and the highest possible length of a word.

Q: What is the highest value and longest word in the English-words dataset?

The highest possible value of a word is 319, and the highest possible length of a word is a char count of 28. There are multiple ways to reach these numbers. You can select the value column and call the max method, call max on the whole DataFrame to compute the statistic for every column, or use describe, which returns the maximum along with the rest of the summary statistics. Sorting with sort_values descending also surfaces the top value.

Summary & Key Takeaways

  • The course, created by Santiago Basulto from DataWars in collaboration with freeCodeCamp, teaches pandas by example. The core philosophy is that just as watching football on TV does not make you a better footballer, watching videos does not make you a data science expert. You have to practice and put your skills to a test with real projects.

  • Each project is a separate chapter, and complexity grows from start to finish, covering data analysis, data cleaning, and data wrangling. Viewers are encouraged to pause the video before each activity and solve it themselves first, then compare with the presented solution, since there are often multiple valid ways to solve the same activity.

  • The first project uses a dataset of English words where the word itself is the index and there are two columns: char count (the length of the word) and value (the sum of the individual character values, where A is 1, B is 2, C is 3, and so on). Activities cover info, shape, describe, .loc selection, and sorting.


Read in Other Languages (beta)

Share This Summary 📚

Explore More Summaries from freeCodeCamp.org 📚