On the previous article we took the first steps to installing python and anaconda, we also went further and looked at the Numpy library. Today we going to have a look at another very important library that is useful in data science Pandas.
Pandas
Pandas is a library used for data manipulation and analysis that has two mainly used data structures:
Series: a one-dimensional structured table (that is, a single column table with index values).
DataFrame: a two-dimensional structured table (simply like tables in a spreadsheet).
We going to take a look on how to create a Series in Pandas, then work on DataFrame onwards. Let’s create a new notebook named Book2 and move on to importing our libraries, this time we’ll also add the Series module.
Let’s create our first Series :
Let’s create conditional statements in our Series
We can now try out Boolean Conditions
Let’s convert our table, ‘animals’, into a dictionary:
You can do more with pandas Series, check out their documentation here.
Let’s move on DataFrame!
We are going to import a dataset file in csv mode, you can download it at kaggle.
First and foremost we going to read the file using the pd.read_csv and print out the first five rows using df.head()
To see the last five rows we do: df.tail(). Note that to see more rows, place your preferred number of rows within the parenthesis.
Now that we have been able to read our file, we can find out the information contained in our dataset:
While checking the information lets also find out our dataset shape:
It’s important to also know the description of your data, as it will help in your analysis:
Another crucial thing when analysing data is to find out if your dataset has any null values as this affects your work and it is very important to find out:
You can use the sum() function to simplify this method :
Here is the documentation for pandas DataFrame For further development, attempt opening non-CSV file formats on pandas, such as HTML, Excel, and JSON .
Let me know your thoughts, any questions and comments. Keep Smiling 🥰🥰