Posts

Introduction to Pandas

                “ Pandas ” – It is an Open-source library in Python . Main purpose of this library is used for data analysis and data manipulation.  It organizes, analyses the data and removes the unwanted data. Panda work like an Excel spreadsheet. Why pandas? It reads the data from various databases. It filters and sorts the records. It handles the missing values. It cleans the messy data. It creates the reports. It also performs the statistical analysis. First, install the pandas. ·        Install Pandas Importing the Pandas: ·        pip install pandas ·        import pandas as pd Creating and Understanding Series in Pandas : A Pandas Series is a one-dimensional name for an array that can store the following data types. Integers Floats Strings Boolean values Mixed data types Let us create a Serie...

Python NumPy Mini Projects :Linear Regression from Scratch

              Let us implement Linear Regression in Python using NumPy. We use the student’s score analysis system. Implementation: Let us create a data set like this as follows… Hours Studied Marks Obtained 2 38 1 20 3 56 4 89 5 76 Let us find the solution for the equation y = mx + b where, y = marks x = study hours m = slope b = intercept Code: #import the numpy import numpy as np #create arrays for input. One is for study hour. Another one is for Mark obtained. x = np.array([2, 1, 3, 4, 5]) y = np.array([38, 20, 56, 89, 76]) #assign the initial values m = 0 b = 0 learning_rate = 0.01 epochs = 1000 n = len(x) #calculate the values for i in range(epochs):     y_pred = m * x + b     dm = (-2/n) * np.sum(x * (y - y_p...

Python NumPy Mini Projects: COVID Data Analysis

               This project deals with COVID Data analysis. COVID has huge impact in the society. It affects the humans around the world. Let us analyse the data. Code Implementation:               This program creates an array of countries. There are three arrays for covid confirmed, covid recovered and those who not survived(death). Calculate the details like total confirmed,total recovered and total death by adding the array elements. Recovery rate is calculated by the below formula, recovery_rate = (recovered / confirmed) * 100. Death rate is calculated by the formula given below, death_rate = (deaths / confirmed) * 100 Maximum Cases are found using max() function. The active cases are also calculated by the formula given here. Active case = Confirmed - Recovered - Deaths Daily cases, Average cases, Maximum and minimum cases are printed using built-in functions. Finally, al...

Python NumPy Mini Projects: Population Statistics dashboard

                 This project implements the Population Statistics Dashboard using NumPy. It shows the analysis of population in various countries and visualise the data. Let us implement the program. Implementation: First, include the NumPy Library. Add the countries and population details into separate arrays. Let us find the total population, average population, minimum population and maximum population using built-in functions. Least and most populated countries are identified using functions. Next. Population percentage and Population share of each country are calculated. Standard deviation and variance values are calculated. Finally, the countries are sorted according to the population. At last, the Population statistics dashboard was printed. Code: import numpy as np countries = np.array([     "India",     "China",     "USA",     "Brazil", ...

Python NumPy Mini projects: Election Vote Counter

              This is the mini project deals with Election Vote Counter. This project has candidate’s list. Voter has to select the candidate. Based on the vote,the winner candidate is selected. Implementation: This implementation starts from including numpy file. First,the candidates list is prepared and displayed. Number of users are received. User has to put the vote for any one of candidate. Based on the vote,those who got the maximum vote is declared as the winner. Python NumPy Code:   import numpy as np # Here is the Candidates list candidates = np.array(["jey", "baby", "sai"]) print("Candidates list:",candidates) # let us Collect the votes n = int(input("Enter number of voters: ")) votes = [] for i in range(n):     vote = input(f"Voter {i+1} vote: ")     votes.append(vote) votes = np.array(votes) # Count the number of votes for each candidate vote_counts = [] for candid...

Python Numpy Mini Projects:Stock Price Analyzer

                 This project analyses the stock prices. It has following functionalities. Code Implementation:               This program starts by creating stock by using NumPy array. The basic statistics include Average price, maximum, minimum prices and standard deviations. Next, Daily price changes are calculated using np.diff(prices). Daily returns price is calculated and the data is rounded to 2 digit. Stock Volatility is calculated and displayed. 7 day moving window is calculated along with average value. Best and worst days are displayed according to the returns value. It shows how a simple 30,000 initial value gives you profit. Code: import numpy as np # Sample stock closing prices prices = np.array([80, 100, 108, 120, 208, 110, 125, 311, 117]) print("Stock Prices:") print(prices) #Basic statistics print("The basic statistics of the da...

Python NumPy Mini Projects: Matrix Operations

                 Matrix is one of the important concepts in mathematics. It has rows and columns.It has many operations to perform as listed below ·        Addition ·        Row wise and column wise Sum ·        Subtraction ·        Element wise Multiplication ·        Multiplication ·        Transpose ·        Determinant ·        Inverse Matrix ·        Rank ·        Eigenvalues and EigenVector 👉Program implementation: import numpy as np rows = int(input("Enter rows: ")) cols = int(input("Enter columns: ")) print("Enter Matrix A:") A = np.array([[int(input()) for j in range(cols)] for i in range(rows)]) print("M...