Python Beginner Steps with Examples
Using the Pandas Library
Pandas is a powerful Python library used for data manipulation and analysis. It provides
data structures like Series (1D) and DataFrame (2D) that make it easy to work with
structured data.
Example: Creating a DataFrame
Here's how you can create a simple DataFrame using Pandas:
import pandas as pd
# Create a dictionary of data
data = {
'Name': ['Alice', 'Bob', 'Charlie'],
'Age': [25, 30, 35],
'City': ['New York', 'Los Angeles', 'Chicago']
}
# Create a DataFrame
df = [Link](data)
# Display the DataFrame
print(df)
Example: Reading Excel Data
Pandas can also be used to read data from Excel files. Here's an example:
import pandas as pd
# Load an Excel file
df = pd.read_excel('[Link]', engine='openpyxl')
# Display the first few rows
print([Link]())
Data Visualization with Matplotlib and Seaborn
Data visualization is a key part of data analysis. Python provides powerful libraries like
Matplotlib and Seaborn to create a wide range of plots and charts.
Line Plot using Matplotlib
Matplotlib is a widely used library for creating static, animated, and interactive
visualizations in Python.
Example:
import [Link] as plt
# Sample data
x = [1, 2, 3, 4, 5]
y = [10, 12, 8, 14, 7]
# Create a line plot
[Link](x, y, marker='o')
[Link]("Sample Line Plot")
[Link]("X-axis")
[Link]("Y-axis")
[Link](True)
[Link]()
Bar Plot using Seaborn
Seaborn is built on top of Matplotlib and provides a high-level interface for drawing
attractive and informative statistical graphics.
Example:
import seaborn as sns
import pandas as pd
import [Link] as plt
# Sample data
data = [Link]({
"Category": ["A", "B", "C", "D"],
"Values": [23, 45, 56, 78]
})
# Create a bar plot
[Link](x="Category", y="Values", data=data)
[Link]("Bar Plot Example")
[Link]()