Informatics Practices
Hindustan Departmental Stores sell items of daily use such as shampoo, soap and much more. They record the entire sale and purchase of goods month-wise so as to get a proper analysis of profit or loss in their business transactions.
Following is the csv file containing the "Company Sales Data".

Read the total profit of all months and show it using a line plot. Total profit data has been provided for each month. Generated line plot must include the following properties:
- X label name = Month Number
- Y label name = Total profit
PyPlot
3 Likes
Answer
import pandas as pd
import matplotlib.pyplot as plt
df = pd.read_csv("C:\\company_sales_data.csv")
profitList = df['total_profit'].tolist()
monthList = df['month_number'].tolist()
plt.plot(monthList, profitList, label = 'Month-wise Profit data of last year')
plt.xlabel('Month number')
plt.ylabel("Profit in dollars")
plt.xticks(monthList)
plt.title('Company profit per month')
plt.yticks([100000, 200000, 300000, 400000, 500000])
plt.show()
Output

Answered By
3 Likes
Related Questions
Assertion (A): Bar graph and histogram are same.
Reasoning (R): A bar graph represents categorical data using rectangular bars. A histogram represents data which is grouped into continuous number ranges and each range corresponds to a vertical bar.
- Both A and R are true and R is the correct explanation of A.
- Both A and R are true but R is not the correct explanation of A.
- A is true but R is false.
- A is false but R is true.
Assertion (A): Marker has different elements i.e., style, color, size, etc.
Reasoning (R): We can customize line of a line chart by using marker property of plot() function.
- Both A and R are true and R is the correct explanation of A.
- Both A and R are true but R is not the correct explanation of A.
- A is true but R is false.
- A is false but R is true.
Anirudh is trying to write a code to plot line graph shown in the figure below. Help him fill in the blanks in the code and get the desired output.

import matplotlib.pyplot as plt # statement 1 x = [1, 2, 3] # statement 2 y = [2, 4, 1] # Statement 3 plt.plot(x, y, color = 'g') # statement 4 ............... # statement 5 ............... # statement 6 # giving a title to graph plt. ............... ('My first graph!') # statement 7 # Function to show the plot ............... # statement 8(i) Which of the above statements is responsible for plotting the values on canvas?
- Statement 8
- Statement 4
- Statement 1
- None of these
(ii) Statements 5 & 6 are used to give names to X-axis and Y-axis as shown in Fig.1. Which of the following can fill those two gaps?
1.
plt.xlabel('X - axis') plt.ylabel('Y - axis')2.
plt.xtitle('x - axis') plt.ytitle('y - axis')3.
plt.xlable('x - axis') pit.ylable('x - axis')4.
plt.xlabel('x axis') plt.ylabel('y axis')(iii) Raman has executed code with first 7 statements but no output is displayed. Which of the following statements will display the graph?
- plt.display()
- plt.show()
- matplotlib.pyplot.display()
- Both (b) & (c)
(iv) The number of markers in the above line chart are:
- Zero
- Three
- Infinite
- Not defined
(v) Which of the following methods will result in displaying 'My first graph!' in the above graph?
- legend()
- label()
- title()
- Both (a) & (c)
Plot a line chart for depicting the population for the last 5 years as per the specifications given below:
plt.title("My Title") will add a title "My Title" to your plot.
plt.xlabel("Year") will add a label "Year" to your X-axis.
plt.ylabel("Population") will add a label "Population" to your Y-axis.
plt.yticks([1, 2, 3, 4, 5]) set the numbers on the Y-axis to be 1, 2, 3, 4, 5. Pass it and label as a second argument. For example, if we use this code plt.yticks([1, 2, 3, 4, 5], ["1M", "2M", "3M", "4M", "5M"]), it will set the labels 1M, 2M, 3M, 4M, 5M on the Y-axis.
plt.xticks() — works the same as plt.yticks(), but for the X-axis.