NUMPY AND MATPLOTLIB PROBLEM
SHEET
1. Find the unique elements and their counts in a NumPy array.
2. Find the sum of all elements in a 2D array along a specific
axis.
3. You are tasked with analyzing the sales data for a retail
store. The sales data is provided as a 2D NumPy array where
each row represents the sales in a particular week, and each
column represents the sales in a specific product category. Use
random to get the 2D array. Do the following:
1. Find the total sales in each product category over the 5
weeks.
2. Calculate the weekly sales for each product category and
find which product category had the highest sales in each week.
3. Calculate the average sales for each product category over
the 5 weeks.
4. Identify the week with the highest overall sales.
4. You work for the HR department of a large company, and you
have been given a dataset containing information on employee
salaries, performance scores, and years of experience. The dataset
is stored in a 2D NumPy array where each row represents an
employee, and the columns are: 1. Salary, 2. Performance Score
(out of 10), 3. Years of Experience
Perform these tasks:
1. Calculate the average salary for employees with more than 5
years of experience.
2. Identify the employee with the highest performance score.
3. Determine the percentage of employees who earn above the
average salary.
4. Identify employees who earn more than $70,000 but have less
than 3 years of experience.
5. Determine the employee with the highest salary and the one
with the lowest salary.
5. You are a data analyst at a financial firm, and you have a dataset
containing the stock prices of 10 companies over the past 30 days.
Each row in the 2D NumPy array corresponds to one company, and
each column corresponds to the stock price on a given day.
Perform the following tasks:
1. Find the company with the highest average stock price over the
30 days.
2. Identify the day when the stock price for all companies was the
highest.
3. Calculate the standard deviation of stock prices for each
company to understand the volatility.
4. Determine which company had the biggest price increase from
the first day to the last day.
5. Find the day with the maximum percentage increase in stock
prices compared to the previous day.
6. You are given the grades of students in a class for an exam. The
dataset contains the scores of 100 students ranging from 0 to 100.
o Create a histogram to visualize the distribution of student
grades.
o Set appropriate axis labels (X-axis: "Grades", Y-axis:
"Number of Students").
o Add a title to the histogram ("Distribution of Student
Grades").
o Customize the color of the bars to make the chart visually
appealing.
7. You have data for various cities (population size) in a country, and
you want to visualize the population distribution. Create a scatter plot
on a map of the country showing each city's population using markers,
where the marker size corresponds to the population size.
8. You are given a dataset with daily COVID-19 cases for a particular
country over the past year. The dataset includes the date and the
number of daily confirmed cases.
o Create a line plot to visualize the daily confirmed COVID-19
cases over time.
o Customize the plot with gridlines, title, axis labels, and a
legend for the moving average.
9. You are given the results of an election with the number of votes
received by each candidate in a particular constituency.
o Create a horizontal bar chart to display the number of votes
for each candidate.
o Convert the vote counts into percentages and display them
as text labels next to each bar.
o Add gridlines, title, and axis labels.
o Use colors to differentiate between candidates and a
legend to indicate the names of the candidates.
10. Get random values for the budget allocation across the
departments IT, accounting, marketing, sales, HR and R&D in a
corporate firm. Represent the data using a pie chart.
1. Display budget allocation values (in currency) along with
the percentage on each slice.
2. Highlight the IT department's budget allocation by
"exploding" its slice.
3. Use distinct colors for each department, ensuring color
contrast is clear.
4. Add a title to the pie chart.