Series
- 02:13
How to use Pandas dataframes and series in Python. How to create, access, and manipulate data structures for data analysis.
Downloads
No associated resources to download.
Glossary
dataframes Pandas Python seriesTranscript
So you've just learned about a new type of object from Pandas called the dataframe. And here you can see an example of what a whole dataframe looks like. It's like a table in Excel with multiple different columns. Now, pandas also gives you another new type of object called the series, and a Pandas series is simply a single column within a Pandas dataframe, or it can be a single column that stands on its own.
In Python you could represent that same data just like you see here, where we've created example data frame by using the pandas read csv function to import a csv file and create a new data frame. And inside this data frame, just like you saw in Excel, we have three columns called series one, series two and series three. So this is a Pandas data frame with three series.
There are two ways to access a series inside a data frame. The first is this first example that you see here where you write the name of the data frame, example data frame, and then a dot followed by the name of the series, series three. When I execute that, it's going to give me only that one column of my data frame.
Alternatively, I can write the name of my data frame and then in square brackets and then in quotes, the name of my series. If I execute this cell, I'm going to get exactly the same result. The difference is if your series name has a space in the title of the series, you might run into problems if you're trying to use this first method of accessing that series inside the data frame. It's fine if the series name is continuous, but if you introduce a space, you're gonna run into problems. On the other hand, using the second example with the square brackets and the quotes, it doesn't matter if you have a space because Python knows that everything within those quotes is the series name. So it doesn't cause a problem if the series name has a space in it. For that reason, most of the time I'm using the second method to access a series.