Python Pandas

Pandas is one of the most widely used libraries in python for all data import/export, manipulation, exploration, and data wrangling tasks.

There are two data structures in Pandas which are important.

  • Pandas Series
  • Pandas DataFrames

Pandas Series

Pandas Series can be imagined as one single column in data. You can create it using the Series() function in Pandas.

A Pandas series can contain data which is numeric as well as character or both.

Below code snippet shows how to define a pandas series. Note that, we have imported pandas as ‘pd’. It means now we can access all pandas functions using pd.

Once you create a pandas series and print it, you can see row indexes getting assigned automatically. It is representing a single column.

If you extract only the values of a series using the .values command, then it will fetch just a numpy array as shown in the last command.

Sample Output:

Pandas Series
Pandas Series

Different ways to create Pandas Series are shown below

Sample Output:

Creating Pandas Series
Creating Pandas Series


Pandas DataFrame

Pandas DataFrames are the representation of rows and columns of data. The data which is present in a csv file, excel file, database table etc, when you read it using pandas, it is stored as a DataFrame.

You can manually create a data frame using the DataFrame() function in Pandas.

The input to DataFrame() function is a list of lists as shown below. It can be a tuple of lists or a list of tuples also. The bottomline is, the data must be passed as a 2-D object, hence, it will represent rows and columns.

Sample Output:

Creating a simple Pandas DataFrame in Python
Creating a simple DataFrame in Python

You can add a new row to this data frame using the append() function. Or add a new column by specifying the column name and passing the values for that column. Apart from this, there are many more useful commands for DataFrames which you can check in Data Manipulation section.

Sample Output:

Adding New rows and columns to the Data Frame
Adding New rows and columns to the Data Frame

Author Details
Lead Data Scientist
Farukh is an innovator in solving industry problems using Artificial intelligence. His expertise is backed with 10 years of industry experience. Being a senior data scientist he is responsible for designing the AI/ML solution to provide maximum gains for the clients. As a thought leader, his focus is on solving the key business problems of the CPG Industry. He has worked across different domains like Telecom, Insurance, and Logistics. He has worked with global tech leaders including Infosys, IBM, and Persistent systems. His passion to teach inspired him to create this website!

Leave a Reply!

Your email address will not be published. Required fields are marked *