Pandas DataFrame & Data Analysis with CSV Files
πΉ What is Pandas?
Pandas is a powerful Python library for data analysis and manipulation. It provides two main data structures:
Series β 1D array with labeled index (like a column)
DataFrame β 2D table with rows and columns (like an Excel spreadsheet)
Pandas is used to:
β
Read & write data from CSV, Excel, SQL, JSON, etc.
β
Perform data cleaning, filtering, sorting, and grouping.
β
Handle missing data.
β
Perform statistical & numerical operations.
β
Merge, join, and reshape datasets.
π Installing Pandas
To use Pandas, install it using:
pip install pandas
Then import it in Python:
import pandas as pd
π Pandas DataFrame
πΒ Creating a DataFrame Using a List
A DataFrame can be created from a list of lists.
β Example 1: Creating a DataFrame
import pandas as pd data = [['Alice', 25], ['Bob', 30], ['Charlie', 35]] df = pd.DataFrame(data, columns=['Name', 'Age']) print(df)
π Creating a DataFrame Using a Dictionary
A DataFrame can be created from a dictionary, where keys represent column names, and values are lists.
β Example 2: Using a Dictionary
data = { "Name": ["Alice", "Bob", "Charlie"], "Age": [25, 30, 35], "City": ["New York", "Los Angeles", "Chicago"] } df = pd.DataFrame(data) print(df)