Posts

Showing posts from August, 2025

Common Objects and their data types in Python

  1. List [] Modifiable (can change values) Ordered (keeps the order of items) Can store mixed data types Example: [1, 2, 3, a, b, c] 2. Tuple () Non Modifiable (cannot change values after creation) Ordered Can store mixed data types Example: (1, 2, 3, a, b, c) 3. Dictionary {} Key-value pair Modifiable Unordered Example: {"name": "Kavi", "age": 25} 4. Set {} Modifiable Unordered (no index) Unique elements only Example: {1, 2, 3} 5. String "" or '' Non Modifiable Ordered Example: "Hello", "world" 6. Integer ( int ) Whole numbers Example: 10 7. Float ( float ) Decimal numbers Example: 3.14 8. Boolean ( bool ) True or False Example: True 9. NoneType ( None ) Represents nothing / null Example: None

What is For Loop in Python?

For loop is used to repeat a code multiple times . It goes through each Value in a Range , one by one, executes the code for each item. How it works: You will write a code inside For Loop. It applies that code to each values in the Range, one by one. You will save time doing this instead of applying the code separately for each values. It only stops the process when it reaches last value in a range.

Methods of List Object in Python

[] is the symbol we use in Python to create a list . A list can hold multiple items of any type (numbers, strings, even other lists ) and we can add, remove, or access items using their position (index). List has some built-in Methods because it’s an object, the ones you often use are methods like: append() – add an item to the end of the list extend() – add multiple items at once insert() – insert item at a specific position remove() – remove a specific item pop() – remove item by index sort() – sort the list reverse() – reverse the list count() – count how many times a value appears index() – find index of a value

Matplotlib Library for Python Visualization

Image
Matplotlib is a Python library for creating visualizations like graphs, charts, and plots. It helps us see data visually , which makes it easier to understand patterns, trends, and relationships. Why Matplotlib is used in Python for Data Science: Easily create line charts, scatter plots, bar charts, histograms, and more. Change colors, labels, titles, legends, figure size, and styles. Works well with Pandas and NumPy data structures.

Scikit-learn Library for Data Science and Machine Learning

Image
Scikit-learn is a Python library for Machine Learning . It has  tools to create models, train data and test models for predicting or classifying data. Why Scikit-learn is used in Python for Data Science: It has Simple functions to train models and make predictions. It Supports many algorithms: Linear Regression, Decision Trees, Random Forest, K-Nearest Neighbors, Clustering, etc. Test Model and Provides metrics like accuracy, r-squared, mean squared error. Prepare data with  Scaling, encoding, splitting data into train / test datasets. Works with NumPy , Pandas , and Matplotlib easily.

Pandas Library in Data Science

Image
Pandas is a Python library for data manipulation and analyzing dataset with rows and Columns. Suitable for working with Large Datasets. Why Pandas is used in Python for Data Science: Stores data in a structured way using Data Frames . Easily handle missing data, duplicates, or incorrect values. Perform calculations, filtering, sorting, grouping, and aggregation. Read and write CSV, Excel, SQL, JSON, and more. Integration with Other Libraries: Works well with NumPy , Matplotlib , Seaborn , and Scikit-learn .

Why Vector, Matrix and Tensor are called 1D, 2D and 3D

1. Vector (1D): A list of numbers in a single line. [1,2,3,4,5] Think of it as a single column or Single Row in Excel. It either goes Horizontal or Vertical or any direction, but Single Line. That is why it is called Only one dimension . Example: [5, 10, 15] → 3 numbers in one row or 3 numbers in one column. Python Code: import numpy as np vector = np.array([1,2,3,4,5]) print(vector) 2. Matrix (2D): A table of numbers with both  rows and columns . Think of it as one Excel sheet where Column A has 1,2,3,4,5 and Column B has 6,7,8,9,10 Now it has Two dimensions: rows × columns. Python Code: import numpy as np matrix = np.array([[1,2,3],[4,5,6],[7,8,9]]) print(matrix) 3. Tensor (3D or more): A collection of matrices stacked together like a . Think of it as multiple Excel sheets stacked in a workbook . One above another. Tensor Can have 3, 4, or more dimensions. Row is one dimension, Column is second dimension, second table or second sheet is third dimension, third table is fourth d...

NumPy Library in Data Science

Image
We use the NumPy library in data science with Python because it makes working with numbers and large datasets much faster and easier. Why NumPy is important in data science: NumPy stores data as arrays that uses less memory Applies Math Operations directly on all values in the array at once. We can work with 1D (vectors), 2D (matrices), and even higher-dimensional data. Libraries like Pandas , Scikit-learn , TensorFlow , and Matplotlib depend on NumPy for handling numeric data. NumPy has built-in functions for matrix multiplication, eigenvalues, random number generation, and statistical calculations.

What is a Python Library?

When we use Python for data analysis, machine learning, or any programming, we do not write each and every code. Why Should we? Some experts already wrote code for us and packed it as a Library. This reusable collection of code is called a Python Library . A library in Python is like a ready-made toolbox. Instead of building every tool yourself, you take the tools from the toolbox and start using it in your code. Why do we need Python Libraries? Save time – We do not write the same code again and again. Easy to use – Just install, import, and start using. Powerful features – Some libraries can do complex tasks in one line of code. Community support – Big communities maintain them, so they keep improving. Examples of Python Data Science Libraries: Pandas – Works with data tables like Excel, filtering and summarizing data NumPy – Works with numbers, arrays, mathematical calculations Matplotlib – Creates graphs and charts Scikit-learn – For machine learning models like regres...

Linear Regression in Python to find Relationship between two columns - Code Explanation

import numpy as np Importing Numpy Library and giving it a short name as np import pandas as pd Importing pandas librabry and giving it a short name as pd from sklearn.linear_model import LinearRegression Importing Linear Regression Model from Sckit Learn Library. import matplotlib.pyplot as plt Importing Matplotlib library for making graphs and giving a short name as plt filepath = r'C:\Users\kkumaran\Downloads\Python - Regression Practice Workbook.xlsx' This is the Location of the Excel File in my Computer. I am importing Excel file into variable called "filepath" data = pd.read_excel(filepath,sheet_name='Linear Regression Practice 1') This code reads the excel file using pandas library and load the sheet Linear Regression Practice 1 into a dataframe called "data". Now your excel data is inside python. print(data) This show the dataset for you to verify. x = data[['Square Feet']] I am creating a variable called x and putting Square feet Col...

Linear Regression in Python to find Relationship between two columns - Formula Explanation

Image
Have you ever noticed in your Life that One thing affects another thing? If Someone Study Well, they score High Marks If Someone Eat Well, they gain Weight If Someone Sleep Well, they remain Younger Doing One thing affects Another thing. But, How much? How much One thing affects Another thing? 50%? 90%? or only 20%? To find that, we use Linear Regression method. Linear Regression Method uses this Formula:  Y = MX + C What is Y: Y is also called as 'Dependent' Value. Because it depends on X. If X Changes, Y Changes. So Y is Dependent value. So we always assign Dependent Column to Variable Y is Python. example: We have 2 Columns. "Study Hours" and "Exam Score" Now, does the Exam score increase when Study Hour increase? YESS! If Someone study more time, their score will obviously increase. So 'Exam Score' Column is depending on 'Study Hours' Column, Right? We call 'Exam Score' Column as Y Column. Because, it is dependent on another Colum...