Python Tutorial – Working with Pandas

What is Pandas?

Below is the excerpt from https://pandas.pydata.org/ :

pandas is an open source, BSD-licensed library providing high-performance, easy-to-use data structures and data analysis tools for the Python programming language.
pandas is a NumFOCUS sponsored project. This will help ensure the success of development of pandas as a world-class open-source project, and makes it possible to donate to the project.

I described Pandas as powerful tool to manipulate data within Python. It is like you have a steroids version of spreadsheet within Python.

How to install Pandas?

Check first if you have the pandas Python package installed in your system. You can use pip3 list to check.

pip3 list

If you see something like:

pandas    0.23.4

You have pandas Python package installed in your system and you are good to go. If you do not see it, you can install pandas Python package by using pip3 install

pip3 install pandas

Basics of Pandas

Making a basic dataframe

Pandas is all about dataframe. Dataframe is a set of data where Pandas can manipulate. Below is the basic example of converting the dataset into Pandasa dataframe.

import pandas as pd

data = {'Toyota':["Corolla", "Camry", "Tacoma", "RAV4"]} 

df = pd.DataFrame(data)
print(df)

You will see an output something like below:

    Toyota
0  Corolla
1    Camry
2   Tacoma
3     RAV4

If you want to sort this in ascending order, you do this by using df.sort_values

Example:

print(df.sort_values(['Toyota'], ascending=True))

The output will be something like below:

    Toyota
1    Camry
3  Corolla
0     Rav4
2   Tacoma

Recent Posts

Feel free to share this post!

Scroll to Top