0% found this document useful (0 votes)
2 views

Introduction to pandas

This document provides an introduction to Pandas, highlighting its importance and applications. It covers key data structures such as Series and DataFrame, along with operations like data cleaning, transformation, aggregation, and merging. The document includes examples for each topic to illustrate the functionality of Pandas.

Uploaded by

Bassel Eissa
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Introduction to pandas

This document provides an introduction to Pandas, highlighting its importance and applications. It covers key data structures such as Series and DataFrame, along with operations like data cleaning, transformation, aggregation, and merging. The document includes examples for each topic to illustrate the functionality of Pandas.

Uploaded by

Bassel Eissa
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 14

Introduction to Pandas

• What is Pandas?
• Importance and applications.
Data Structures
• Pandas provides two primary data structures:
• - Series: 1-dimensional labeled array
• - DataFrame: 2-dimensional labeled data
structure
Example: Creating a Series and
DataFrame
• Creating a Series:
• import pandas as pd
• s = pd.Series([1, 3, 5, 7, 9])
• Creating a DataFrame:
• data = {'A': [1, 2, 3], 'B': [4, 5, 6]}
• df = pd.DataFrame(data)
DataFrame Operations
• Common operations on DataFrames:
• - Viewing data: head(), tail()
• - Selecting data: loc[], iloc[]
• - Filtering data: df[df['A'] > 1]
Example: DataFrame Operations
• Viewing data:
• df.head()
• Selecting columns and rows:
• df['A'], df.loc[0]
• Filtering data:
• df[df['A'] > 1]
Data Cleaning
• Handling missing data and duplicates:
• - Filling missing values: fillna()
• - Dropping missing values: dropna()
• - Removing duplicates: drop_duplicates()
Example: Data Cleaning
• Filling missing values:
• df.fillna(0)
• Dropping missing values:
• df.dropna()
• Removing duplicates:
• df.drop_duplicates()
Data Transformation
• Adding and modifying columns:
• - Adding a new column: df['C'] = [7, 8, 9]
• - Applying functions: df['A'].apply(lambda x:
x*2)
Example: Data Transformation
• Adding a new column:
• df['C'] = [7, 8, 9]
• Applying a lambda function:
• df['A'] = df['A'].apply(lambda x: x*2)
Data Aggregation and Grouping
• GroupBy operations and aggregation
functions:
• - Grouping data: df.groupby('A')
• - Aggregation: df.groupby('A').sum()
Example: Data Aggregation and
Grouping
• Grouping data:
• grouped = df.groupby('A')
• Applying aggregation functions:
• grouped.sum()
Merging and Joining
• Combining DataFrames:
• - Merging: pd.merge(df1, df2, on='key')
• - Joining: df1.join(df2, on='key')
Example: Merging and Joining
• Merging two DataFrames:
• merged_df = pd.merge(df1, df2, on='key')
• Joining DataFrames:
• joined_df = df1.join(df2, on='key')
Summary
• In this session, we covered:
• - Data structures
• - DataFrame operations
• - Data cleaning
• - Data transformation
• - Data aggregation and grouping
• - Merging and joining
• Q&A session
• Thank you!

You might also like