Practical Record File X - DS
Practical Record File X - DS
Objective:
o To create a 2D array using NumPy, which allows for efficient manipulation and
mathematical operations on arrays.
Task:
o Import NumPy library.
o Create a 2D array with specific values or random values.
o Print the 2D array to verify its structure.
Code:
# Importing the numpy library
import numpy as np
Objective:
o To convert a Python list into a NumPy array, enabling more efficient mathematical
operations and array manipulations.
Task:
o Import the NumPy library.
o Create a Python list.
o Convert the list to a NumPy array using the np.array() method.
o Print the resulting NumPy array.
Code:
Objective:
o To create a 4x5 matrix filled with numbers ranging from 11 to 30 using NumPy. This will
allow you to explore matrix creation and indexing in NumPy.
Task:
o Import the NumPy library.
o Generate a sequence of numbers from 11 to 30.
o Reshape the sequence into a 4x5 matrix using np.reshape().
o Print the resulting 4x5 matrix.
Code:
# Importing the numpy library
import numpy as np
Objective:
o To create a pandas DataFrame to organize and store data of candidates who appeared in
interviews. The DataFrame will contain candidate details such as name, score, number of
attempts, and whether they qualify for the next round.
Task:
o Import the pandas library.
o Create a DataFrame to store candidate details.
o Define the columns as 'name', 'score', 'attempts', and 'qualify'.
o Assign custom row indices such as C001, C002, etc.
o Display the DataFrame to verify the results.
Code:
# Importing the pandas library
import pandas as pd
Objective:
o To create a pandas DataFrame to store information about players, including their team,
number of matches, runs, and average score. The program filters and displays only the
players whose total runs exceed 1000.
Task:
o Import the pandas library.
o Create a DataFrame named player with columns: 'team', 'no. of matches', 'runs', and
'average'.
o Set the player names as the row index.
o Display only the players whose total runs are greater than 1000
Code:
# Importing the pandas library
import pandas as pd
Objective:
o To visualize the ratings of different mobile games on a bar chart. This helps in easily
comparing the ratings of the games.
Task:
o Import the necessary libraries (matplotlib and numpy).
o Define the list of games and their respective ratings.
Code:
Objective:
o To calculate the variance and standard deviation for a given dataset. Variance measures
the spread of data, and standard deviation is the square root of the variance, providing a
measure of the average distance from the mean.
Task:
o Import the necessary library (numpy).
o Define the given dataset.
o Calculate the variance and standard deviation using the appropriate functions from
numpy.
o Display the results.
Code:
# Given data
data = [33, 44, 55, 67, 54, 22, 33, 44, 56, 78, 21, 31, 43, 90, 21, 33, 44, 55, 87]
Objective:
o To create a menu-driven program that calculates and displays the mean, mode, and
median for a given dataset. These are fundamental statistical measures used to describe
the central tendency of data.
Task:
o Create a menu that allows the user to select between calculating mean, mode, and
median.
o Implement the functionality for each option using appropriate Python functions.
o Display the results based on the user's selection.
Code:
# Importing necessary libraries
import statistics
# Given dataset
data = [5, 6, 1, 3, 4, 5, 6, 2, 7, 8, 6, 5, 4, 6, 5, 1, 2, 3, 4]
# Menu-driven program
def menu():
while True:
print("\nMenu:")
print("1. Calculate Mean")
print("2. Calculate Mode")
print("3. Calculate Median")
print("4. Exit")
if choice == 1:
mean = calculate_mean(data)
print(f"Mean: {mean}")
elif choice == 2:
mode = calculate_mode(data)
print(f"Mode: {mode}")
elif choice == 3:
median = calculate_median(data)
print(f"Median: {median}")
elif choice == 4:
print("Exiting the program...")
break
else:
print("Invalid choice. Please try again.")
19.Consider the following data of a cloths store and plot the data on the
line chart and customize the chart as you wish:
Month Jeans T-Shirts Shirts
March 1500 4400 6500
April 3500 4500 5000
May 6500 5500 5800
June 6700 6000 6300
July 6000 5600 6200
August 6800 6300 4500
Title:
o Plotting Sales Data of Clothes Store on a Line Chart
Objective:
o To represent the sales data of various clothing items (Jeans, T-Shirts, and Shirts) over
several months on a line chart, and customize the chart with a title, axis labels, and
legends to make it visually appealing.
Task:
o Define the data for each clothing item (Jeans, T-Shirts, and Shirts) for the months from
March to August.
Code:
20.Observe the given data for monthly sales of one of the salesmen for 6
months. Plot them on the line chart.
Month January February March April May June
Sales 2500 2100 1700 3500 3000 3800
Title:
o Sales Stats - Monthly Sales of a Salesman
Objective:
o To visualize the monthly sales data of a salesman on a line chart with specific
customizations, including dashed lines, custom markers, legends, and labeled axes.
Task:
o Plot the sales data of a salesman for six months (January to June).
o Apply customizations such as:
o Title of the chart as "Sales Stats".
o X-Axis labeled as "Month".
o Y-Axis labeled as "Sales".
o Display legends for the plot.
o Use dashed lines with a width of 5 points.
o Set the line color to red.
o Use dot markers with blue edge color and black fill color.
Code: