Python for Data Analysis: A Practical Step-by-Step Guide
Python has become the go‑to language for data analysis thanks to its powerful libraries and readable syntax. Whether you are cleaning a messy dataset, exploring trends, or building reports, Python offers a smooth workflow. This tutorial covers the essential steps to get you from raw data to actionable insights.
First, install the core libraries: pandas for data manipulation, NumPy for numerical operations, matplotlib or seaborn for visualisation, and Jupyter Notebook for an interactive environment. Run pip install pandas numpy matplotlib seaborn jupyter to get started.
Load and Explore Your Data
Begin by reading a CSV file with pandas:
import pandas as pddf = pd.read_csv('your_data.csv')- Use
df.head()to preview the first rows anddf.info()to see column types and missing values. - Generate summary statistics with
df.describe().
Clean and Transform Data
Real‑world data is rarely perfect. Common cleaning steps:
- Drop duplicates:
df.drop_duplicates(inplace=True) - Fill missing numeric values (e.g., with the median):
df['column'].fillna(df['column'].median(), inplace=True) - Filter rows:
df_filtered = df[df['age'] > 30] - Group and aggregate:
df.groupby('category')['sales'].sum()
Visualise Insights
Quick plots help you spot patterns:
- Histogram:
df['column'].hist() - Boxplot:
df.boxplot(column='sales', by='region') - Correlation heatmap using seaborn:
import seaborn as sns; sns.heatmap(df.corr())
Use plt.show() after importing matplotlib.pyplot as plt to display the chart.
Conclusion
With just a few lines of Python, you can load, clean, explore, and visualise data effectively. Practice on public datasets (e.g., from Kaggle or UCI) and gradually add more advanced techniques like feature engineering or machine learning. Python makes data analysis accessible—start small and iterate.