Welcome to the Python Projects Repository! This repository hosts multiple beginner-to-intermediate level Python-based projects with well-documented code and practical demonstrations. Explore two main projects included here:
A comprehensive, beginner-to-intermediate Python tutorial series using Jupyter Notebook. This project introduces Python fundamentals and transitions smoothly into powerful data manipulation using the Pandas library.
- Introduction
- Python Data Types
- Control Structures
- Functions & Lambda Expressions
- File Input/Output
- Pandas Library
- Series
- DataFrames
- Data Viewing & Manipulation
Python is a high-level, interpreted programming language known for its readability, simplicity, and vibrant community. Itβs ideal for:
- Data analysis
- Web development
- Automation
- Scientific computing
- Variables: Dynamically typed
- Numeric Types:
int
,float
,complex
- Strings: Immutable sequences
- Lists: Mutable ordered collections
- Dictionaries: Key-value mappings
- Tuples: Immutable sequences
- Sets: Unordered collections of unique items
- Relational:
==
,!=
,<
,<=
,>
,>=
- Logical:
and
,or
,not
,in
,not in
- Conditional Statements:
if
,elif
,else
- Loops:
for
,while
, nested loops supported
- Defined using
def
- Anonymous functions using
lambda
- Usage with
map()
,filter()
,reduce()
Example:
square = lambda x: x ** 2
print(square(4)) # Output: 16
input()
for keyboard input- File modes:
"r"
,"w"
,"a"
,"r+"
,"a+"
- Operations:
read()
,write()
,close()
,seek()
,tell()
- File management:
os.rename()
,os.remove()
A high-performance library for data analysis and manipulation.
- 1D labeled arrays
- Supports slicing, indexing, vectorized operations
- Constructed from
dict
,ndarray
, or scalar
- 2D labeled data structure
- Constructed from lists of dicts, dict of Series, structured arrays, etc.
- Column/row selection
- Arithmetic operations
- Transposing with
.T
- Sorting:
.sort_values()
,.sort_index()
- Boolean indexing and filtering
.head()
,.tail(n)
,.describe()
- Indexing with
.loc[]
,.iloc[]
- Boolean filtering using
.isin()
and conditions
-
π₯ Install Anaconda
π Download Anaconda -
π Launch Jupyter Notebook
- Start via Anaconda Navigator
- Or run in terminal:
jupyter notebook
-
π Open the Notebook
- Navigate to
Python-Tutorials.ipynb
- Navigate to
-
βΆοΈ Run Cells- Use
Shift + Enter
to execute cells
- Use
A simple yet effective demonstration of using NLTK (Natural Language Toolkit) to split a paragraph into individual sentences.
import nltk
from nltk.tokenize import sent_tokenize
text = "All the great players and great people have one thing in common. They work even harder when no one is watching them."
sentences = sent_tokenize(text)
print(sentences)
Output:
['All the great players and great people have one thing in common.', 'They work even harder when no one is watching them.']
sent_tokenize()
uses a pre-trained Punkt tokenizer.- To use it for the first time:
nltk.download('punkt')
This program:
- Loads a paragraph of text.
- Splits the paragraph into individual sentences.
- Prints the result as a list of strings.
This project demonstrates how to perform label encoding using Python in a Jupyter Notebook. Label encoding is a data preprocessing technique used in machine learning to convert categorical labels into numeric form so that algorithms can work effectively with the data.
Label_Encoding.ipynb
: Jupyter notebook that contains Python code for performing label encoding on a sample dataset usingpandas
.
- Understand the concept of label encoding
- Create a sample dataset with categorical features
- Apply label encoding using different methods
- Analyze the effects of encoding on the dataset
- Python 3
- pandas
- numpy
- Jupyter Notebook
The notebook starts by importing necessary libraries:
import pandas as pd
import numpy as np
A sample dataset is created with one or more categorical columns that require encoding. These columns represent categories like Country
, Color
, Gender
, etc.
Label encoding is applied using:
pandas.factorize()
pandas.Categorical().codes
Example:
df['encoded'] = pd.factorize(df['category_column'])[0]
The encoded results are compared with the original data to understand the transformation.
- Preparing categorical data for machine learning models
- Converting textual class labels to integers
- Encoding target labels in supervised learning
- Ensure that the categorical variables are ordinal if using Label Encoding.
- For nominal (non-ordered) categories, consider using One-Hot Encoding to prevent unintended ordinal relationships.
Label Encoding assigns each unique category value an integer, which can introduce unintended order relationships. Be cautious when using it with nominal data.
Python-Projects-Repo/
βββ Python-Basic/
β βββ Python_Assignment_1.ipynb
β βββ README.md
βββ Python_NLP/
β βββ Python_NLP.ipynb
β βββ README.md
βββ Label-Encoding-Tutorial/
β βββ Label_Encoding.ipynb
β βββ README.md
βββ README.md <-- [You are here]
Muhammad Saeed
BSc Electrical Engineering
Expert in Python, Embedded Systems, and AI Applications
Happy Coding! π