Menu

Introduction to Pandas and Its Data Structures

Introduction to Pandas and Its Data Structures

Pandas is a Python library used to organize, manipulate, and analyze structured data. It is especially useful when working with spreadsheets, CSV files, database records, and datasets containing rows and columns.

Pandas builds on NumPy and provides two important data structures: Series and DataFrame.

Understanding a Series

A Series is a one-dimensional labeled collection of values. You can think of it as a single column of data.

import pandas as pd

sales = pd.Series([12000, 15000, 18000, 22000])

print(sales)

Each value has an associated index. By default, Pandas assigns integer indexes starting from zero.

You can also provide custom labels.

sales = pd.Series(

[12000, 15000, 18000],

index=["January", "February", "March"]

)

print(sales["February"])

Custom indexes make data easier to interpret because values can be accessed using meaningful labels.

Understanding a DataFrame

A DataFrame is a two-dimensional tabular structure with labeled rows and columns. It is one of the most commonly used objects in data science.

import pandas as pd

data = {

"Product": ["Laptop", "Tablet", "Phone"],

"Price": [55000, 25000, 30000],

"Units_Sold": [12, 20, 35]

}

df = pd.DataFrame(data)

print(df)

Output:

Product  Price  Units_Sold

0  Laptop  55000          12

1  Tablet  25000          20

2   Phone  30000          35

Each row represents a product, while each column represents an attribute. This structure makes it easy to filter records, calculate statistics, and prepare data for visualization or machine learning.


Python for Data Science

VA

Vishalini A



Learn via Video Course

undefined Logo

NaN hrs



Get in Touch For Details