Pandas is an open-source library designed primarily for working quickly and logically with relational or labelled data. It offers a range of data structures and procedures for working with time series and numerical data. The NumPy library serves as the foundation for this library. Pandas is quick and offers its users exceptional performance & productivity.

  1. Advantages
    For altering and analysing data, it is quick and effective.
  2. It is possible to load data from different file objects.
  3. Simple handling of missing data in both floating point and non-floating point data (expressed as NaN)
  4. Size mutability: columns in DataFrame and higher-dimensional objects can be added and removed.
  5. joining and merging of data sets.
  6. Versatile data set reshaping and pivoting
    time-series functionality is included.
  7. Effective group by functionality for splitting, applying, and combining data sets.

Get Going

Checking to see if pandas is installed in the Python folder is the first step in using it. If not, we must use the pip command to install it on our machine. Enter the command cmd in the search box, and then use the cd command to find the location where the python-pip file is installed. Locate it and enter the following command:

 


You must import the library after installing pandas on your computer. Typically, this module is imported as:

bring in pandas as pets
Pd is used as a shorthand for the Pandas in this sentence. Although it is helpful to write less code each time a method or property is called, utilising the alias to import the library is not required.

In general, Pandas offers two data structures for data manipulation, namely:

Series
DataFrame

 

Before you can use Pandas, you need to make sure it’s installed on your system. You can install it using pip, Python’s package manager. Open your terminal or command prompt and run:
pip install pandas

Importing Pandas

Once Pandas is installed, you can import it into your Python environment. Conventionally, Pandas is imported with the alias ‘pd’:
import pandas as pd

Basic Data Structures

Pandas provides two primary data structures: Series and DataFrame. Series: A one-dimensional array-like object that can hold various data types. It’s similar to a column in a spreadsheet or a single variable in statistics.
# Creating a Series from a list
data = [1, 2, 3, 4, 5]
series = pd.Series(data)
print(series)
DataFrame: A two-dimensional table with rows and columns, similar to a spreadsheet or a SQL table
# Creating a DataFrame from a dictionary
data = {‘Name’: [‘Alice’, ‘Bob’, ‘Charlie’],
        ‘Age’: [25, 30, 35]}
df = pd.DataFrame(data)
print(df)

Loading Data

Pandas can load data from various sources, such as CSV files, Excel spreadsheets, SQL databases, and more.
# Reading a CSV file into a DataFrame
df = pd.read_csv(‘data.csv’)
Loading data from an Excel file:
# Reading an Excel file into a DataFrame
df = pd.read_excel(‘data.xlsx’)

Data Exploration and Inspection

Once you have data loaded into Pandas, you can start exploring and inspecting it. Viewing the first few rows of a DataFrame
# Display the first 5 rows
print(df.head())
Getting information about the DataFrame: # Display basic information about the DataFrame
print(df.info())
Descriptive statistics of the data:
# Generate summary statistics
print(df.describe())