Hello, my name is Nazar Dajani, and in these lessons, you will learn about the popular Python libraries used to work with data. In this lesson, you will learn about the Pandas library. Pandas is a popular open source library in Python that provides data manipulation and analysis capabilities. It was created by Wes McKinney in 2008 and has since become a critical tool for data scientists, analysts, and programmers working with data in Python. And if you are curious about the origin of the library's name, the name Pandas is derived from the term panel data, which is an econometrics term for multi-dimensional structured data sets. Now, Pandas provides two primary data structures, series and data frames. These data structures are designed to handle a wide variety of data types and are optimized for performance. A series is like a column in a table. It's a one-dimensional labeled array capable of holding any data type, for example, integers, strings, floating point numbers, objects, and so on. Let me show an example to better illustrate this concept. Here's a very short code example. On the first line, I have to import the pandas library since it's not native to the Python interpreter, and I include the as keyword, so I can alias the word pandas with just PD. Now, for this code to work, I must have the pandas library installed already. And to install pandas, one quick way is to run a pip install command from my terminal window. So I'll open a terminal window, then I'll type pip install, which is the command to install a library in your Python environment. Then I'll follow it by the library's name. So in this case, I'll just type pandas. Then I enter. Now the results I get indicate they already have pandas installed. But if this was my first time, I would get some different output. So the goal is to make sure that you have pandas installed before you can use it in your Python code. All right, now that I have pandas ready for use, I can call its many classes, methods, properties, and attributes. So my second line of code simply calls the series class and passes it an array of integers. Then I take the series and assign it to a variable called s. And to see what this series looks like, I have a print statement. Now let me run this code. And this is what I get. Here is my series of data, which is a column of data that was passed in this array. But what is this other column here that starts with zero and increments by one? This is what is called a label, and it uses an index based system. So that's why it starts with zero and increments by one. You see, to identify our data, we need to label it so we could reference it. For example, if I want to point out the value seven in our series, I can say item number three, because three is the index or the label that I use to identify the value seven. You can also think of it as a line or a row number. Or again, it's a label to identify your data. Now this index label column doesn't have to use a generic index number notation. I can use an attribute called index, which is part of the series class to control how I want my labels to look like. For example, I'll now modify my code to add an index attribute. And I'll set it equal to an array of letters. And now when I run this code again, I see that the index column no longer uses the generic 01234 labels. But instead, it's using what I passed in the index attribute. So you can see that you have full control over how your data can look like, which is what the pandas library is all about. Now, please do make sure you specify the correct number of items in your index attribute as your data series. Because if you don't, you will get an error. And in my example, I have five data items. So I must match this count for my index count as well. For example, I'll remove the last index item. So now I have five items in my series, but only four items in my index, which is not a correct match. And if I run it now, I get an error that the five count items do not match the four index count. So again, just be careful that your data matches your index label. All right, now we know that working with data is usually more than a one dimensional affair. And so pandas gives us what is called a data frame. A data frame is a two dimensional, labeled data structure with columns of potentially different types. It is similar to a spreadsheet or a database table or a dictionary. Basically, a data frame has both rows and columns. And here's a code example to help demonstrate the data frame concept. I start with my usual import pandas speedy statement. Then on the next line, I define my data. Here, I'm using a dictionary of three key value pairs. My keys will become my column headers or labels, while the values will be my rows data. So I'm building my data frame to have a first column called column one, with integer data of one, two, and three. Then my second column is called column two, with string data of a B and C. And my third column is called column three, with floating data of 0.1, 0.2, and 0.3. And I take this dictionary and I sign it to a variable called data. Now, how can I use this data to create my pandas data frame? Well, on the next line, I call the data frame class, which is part of the pandas library. And I pass it my data, which in this case is my variable name called data. It's very similar to what I did in my previous example. Up here, I call the series class and pass it my data. And down here, I'm calling my data frame class and passing it my data as well. But we saw that the series data return just one column, again, because it's one dimensional. But now data frames are two dimensional, and I'll run this code to see it in action. And there you go. I now have a table looking structure, which is the pandas data frame with columns and rows. I also do get the index label column by default. And I can change that just like I did with this series example. So I'll modify this code. And when I run my code again, I see the index column has been updated accordingly. And this data frames also come with a myriad of methods. And I highly suggest you explore the documentation. But two very common methods are the head and tail methods. So for example, if I just type df.head and I run this code, I get the entire data set, the head method by default returns the first five rows of data with the header row as well. If I want more or less rows, I can control them by passing the number as an argument. So say I just want the first row of data in my data set, then I can add one in my parentheses, then run this code again. And voila, I only get the very first row. Now the opposite of the head method is the tail method. It basically returns the last five rows in your data set by default. So if I type df.tail and run this code, I still get the full table because I only have three rows total. And just like the head method, I can pass the number one as an argument. And when I run it, I only get the last row in my table. So now we saw that we can get data into a Panda series or data frames. And our source of data can vary. My two examples were just hard coded data sources. But I can also get data frame from a CSV file, an Excel spreadsheet, JSON, or a database. But this isn't the first step, which is to load the Panda's data frame with data. Then we can do so much of that data. For example, Panda's provides numerous functions for handling missing or inconsistent data, such as filling in missing values, dropping missing values, and interpolating values. Panda's also allows you to filter and select data based on the conditions or specific columns and rows. Panda's also offers a wide range of functions for transforming data, such as renaming columns, inverting data types, aggregating, pivoting, and reshaping data. And for data analysis, Panda's provides built-in functions for descriptive statistics, correlations, and time series analysis, among other analytical tasks. In summary, Panda's is a powerful library for data manipulation and analysis in Python. It simplifies many tasks related to data cleansing, transformation, and analysis by providing flexible and efficient data structures and a rich set of functions. So as a result, Panda's has become an essential tool for data scientists, analysts, and Python developers working with data. And in the next lesson, you will learn about the NumPy library. Thanks for watching.