π Starting My Journey with Pandas β Day 1
Weβve just started learning Pandas, a powerful Python library used for:
-
π Data manipulation
-
π Data analysis
-
π Handling large files (
.csv
,.xlsx
,.json
)
πΌ What is Pandas?
The name Pandas comes from:
-
"Panel Data" (a term from statistics)
-
"Python Data Analysis"
Pandas was created by Wes McKinney in 2008. It provides easy-to-use functions for:
-
Analyzing data
-
Cleaning and transforming data
-
Exploring and saving datasets
βοΈ Getting Started with Pandas
Step 1: Install and Import
pip install pandas
import pandas as pd
* pd
is an alias (shortcut name) that we use instead of typingpandas
every time.
π Reading Different File Types
df = pd.read_csv("filename.csv", encoding="Latin1")
df = pd.read_excel("filename.xlsx")
df = pd.read_json("filename.json")
print(df)
CSV
= Comma Separated Values
XLSX
= Excel File
JSON
= JavaScript Object Notation
π§ͺ Creating and Saving Data
data = {
"Name": ["Ram", "Shyam", "Ghanshyam"],
"Age": [10, 20, 30],
"City": ["Nagpur", "Mumbai", "Delhi"]
}
df = pd.DataFrame(data)
print(df)
Save the Data
df.to_csv("output.csv", index=False)
df.to_excel("output.xlsx", index=False)
df.to_json("output.json", index=False)
π Exploring the Dataset
print(df.info()) # Dataset summary
print(df.head()) # First 5 rows
print(df.tail()) # Last 5 rows
print(df.describe()) # Stats summary
print(df.shape) # Shape as (rows, columns)
print(df.columns) # List of column names
π― Accessing Columns
1. Single Column:
name_col = df["Name"]
print(name_col)
2. Multiple Columns:
multi_col = df[["Name", "Age"]]
print(multi_col)
β Final Thoughts
This is just the beginning of my Pandas journey! π
Next, Iβll explore how to filter data, handle missing values, and visualize data using Pandas and Matplotlib.
If youβre also learning Pandas or working with Python, feel free to share your experience or tips in the comments! π
Comments
Post a Comment