A comprehensive Jupyter notebook demonstrating 40+ essential NumPy and Pandas functions with practical examples and outputs.
This educational resource provides hands-on examples of commonly used NumPy and Pandas functions. Each function includes:
- Clear explanations
- Code examples
- Expected outputs
- Use cases
Perfect for beginners learning data manipulation in Python or as a quick reference guide for experienced developers.
This notebook serves as:
- Learning Resource: Step-by-step introduction to NumPy and Pandas
- Quick Reference: Easy-to-navigate examples of common operations
- Practice Material: Code you can run and modify to learn by doing
Array Creation:
np.eye()- Create identity matricesnp.diag()- Create diagonal matrices or extract diagonal elementsnp.indices()- Generate index arraysnp.zeros()- Create arrays filled with zerosnp.ones()- Create arrays filled with onesnp.arange()- Create sequences of numbersnp.linspace()- Create evenly spaced numbersnp.random()- Generate random numbers
Array Operations:
np.copy()- Create deep copies of arraysnp.array()- Convert lists to arraysnp.reshape()- Change array dimensionsnp.flatten()- Convert to 1D arraynp.transpose()- Transpose arraysnp.concatenate()- Join arrays
Mathematical Operations:
np.sqrt()- Square rootnp.sin(),np.cos()- Trigonometric functionsnp.mean(),np.median()- Statistical functionsnp.sum(),np.prod()- Aggregation functions
DataFrame Creation:
pd.DataFrame()- Create DataFramespd.Series()- Create Seriespd.read_csv()- Read CSV files- Dictionary to DataFrame conversion
Data Manipulation:
df.head(),df.tail()- View datadf.describe()- Statistical summarydf.info()- DataFrame informationdf.drop()- Remove rows/columnsdf.rename()- Rename columnsdf.sort_values()- Sort datadf.groupby()- Group datadf.merge()- Merge DataFrames
Data Analysis:
df.mean(),df.median()- Statistical measuresdf.value_counts()- Count unique valuesdf.isnull()- Detect missing valuesdf.fillna()- Fill missing valuesdf.corr()- Correlation matrixdf.dot()- Matrix multiplication
Data Selection:
.loc[]- Label-based indexing.iloc[]- Integer-based indexing- Boolean indexing
- Column selection
- Python 3.x
- NumPy: Numerical computing library
- Pandas: Data manipulation and analysis library
- Python 3.7 or higher
- pip package manager
- Clone the repository:
git clone https://github.com/yourusername/numpy-pandas-reference.git
cd numpy-pandas-reference- Install required packages:
pip install numpy pandasOr use the requirements file:
pip install -r requirements.txt- Run the notebook:
jupyter notebook Winfred_Njiru__1_.ipynb- Upload the notebook to Google Colab
- All libraries are pre-installed
- Run cells sequentially using
Shift + Enter
# Install Jupyter if you don't have it
pip install jupyter
# Start Jupyter Notebook
jupyter notebook
# Open Winfred_Njiru__1_.ipynbEach code cell can be:
- Run independently: Execute to see the output
- Modified: Change values to experiment
- Expanded: Add your own examples
The notebook is organized into 40 numbered sections:
1-10: Basic NumPy array creation and manipulation
11-20: Advanced NumPy operations
21-30: Pandas DataFrame basics
31-40: Advanced Pandas operations
import numpy as np
# Create a 3x3 identity matrix
identity = np.eye(3, 3)
print(identity)
# Output:
# [[1. 0. 0.]
# [0. 1. 0.]
# [0. 0. 1.]]import pandas as pd
# Create a DataFrame
df = pd.DataFrame({
'Name': ['Alice', 'Bob', 'Charlie'],
'Age': [25, 30, 35]
})
# Get statistical summary
print(df.describe())For Complete Beginners:
- Start with NumPy array creation (sections 1-5)
- Move to basic operations (sections 6-10)
- Learn Pandas DataFrames (sections 21-25)
- Practice data manipulation (sections 26-30)
For Quick Reference:
- Use the table of contents
- Jump to specific function examples
- Copy and modify code for your needs
- Fast numerical computations
- Multi-dimensional array operations
- Mathematical and statistical functions
- Broadcasting capabilities
- Handling tabular data
- Data cleaning and preparation
- Time series analysis
- Statistical analysis
- Data visualization integration
Contributions are welcome! You can:
- Add more function examples
- Improve explanations
- Fix errors or typos
- Add visualizations
- Suggest new topics
How to contribute:
- Fork the repository
- Create a feature branch (
git checkout -b feature/NewFunction) - Commit your changes (
git commit -m 'Add new function example') - Push to the branch (
git push origin feature/NewFunction) - Open a Pull Request
This project is open source and available under the MIT License.
Winfred Mutitu Njiru
- Email: winniemutitu@outlook.com
- NumPy documentation: https://numpy.org/doc/
- Pandas documentation: https://pandas.pydata.org/docs/
- Python community for best practices
- NumPy quickstart tutorial
- Pandas 10 minutes to pandas guide
- Data analysis with Python courses
Quick reference to find specific functions:
NumPy:
eye, diag, indices, copy, array, zeros, ones, arange, linspace, random, reshape, flatten, transpose, concatenate, sqrt, sin, cos, mean, median, sum
Pandas:
DataFrame, Series, read_csv, head, tail, describe, info, drop, rename, sort_values, groupby, merge, mean, median, value_counts, isnull, fillna, corr, dot, loc, iloc
If you have questions or need help:
- Open an issue in the repository
- Email: winniemutitu@outlook.com
- Check official documentation for detailed information
β If you find this resource helpful, please consider giving it a star!
Happy Learning! π