Innovative Worksheet For Python (Basics)

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 4

Class XII (IP)

Question Bank (July)


Topic: CSV & Data Visualization (Python)
PS:- Solve the following questions and write the answers in IP notebook.
1. Which of the given statements is incorrect with regards to CSV?
a. Complex format for data storage.
b. A common format for data interchange.
c. It can be opened in popular spreadsheet packages like MS Excel, Calc etc.
d. Nearly all spreadsheets and databases support import /export to csv format.
2. Write a program that reads from a csv file where the separator character is ‘$’. Read
only first 5 rows in your dataframe.
a. Given column headings as ItemName, Quantity, Price
b. Make sure to read first row as data and not column headers.
c. The path of the file is “c:\data\data.csv”
3. Use the Data frame “Sales” to do the following:
2014 2015 2016 2017
MADHU 100.5 1200 20000 50000
0
KUSUM 150.8 1800 50000 60000
0
KINSHU 200.9 2200 70000 70000
K 0
ANKIT 30000 3000 100000 80000
0
SHRUTI 40000 4500 125000 90000
0
a. Write the values of dataframe Sales to a CSV named SalesFigure.csv on the disk. Do
not write the row labels and column labels.
b. Read the data in the file Salesfigure.csv into a Dataframe named SalesRetreived and
display it. Now update the row labels and column labels of SalesRetreived to be the
same as that of sales (made in part (a)).
4. Are the following two statements same? Why /Why not?
a. pd.read_csv(‘zoo.csv’, sep= ‘;’)
b. pd.read_csv(‘zoo.csv’)
5. Mr. Priyank is in a game development industry and he was comparing the given chart
on the basis of the ratings of the various games available on the play store.
He is trying to write a code to plot the graph. Help Mr. Priyank to fill in the blanks of the code
so that he can get the desired output.
import ______________________________ #Statement 1 (write the relevant library)
Games= [“Subway Surfer” , “Temple Run” , “Candy Crush”, “Bottle Shot”, “Runner Best”]
Rating = [4.2, 4.8, 5.0, 3.8, 4.1]
plt. ________________ (Games, Rating) #Statement 2 (to plot the graph)
plt. xlabel(“Games”)
plt. ______ (“Rating”) #Statement 3 (to display it on Y axis)
plt. ________ #Statement 4 (to display the plot)
Write the commands for Statement 1 -4.
6. Sachin has written a Python code to create a bar plot as given below using the following
data:

City Happiness_Index_Male Happiness_Index_Female


Delhi 60 30
Beijing 40 60
Washington 70 70
Tokyo 65 55
Moscow 85 75
import ___________ as ____________ # Statement 1
City= [“Delhi”, “Beijing”, “Washington”, “Tokyo”, “Moscow”]

Gender = [“Male”, “Female]


Happiness_Index_Male = [60,40,70,65,85]
Happiness_Index_Female = [30,60,70,55,75]
plt.____ ([7.5,1.75,2.75,3.75,4.75], Happiness_Index_Female, color= ‘Green’, width=.5,
label = “Female) # Statement 2
pos=range(len(City))
print(pos)
plt.xticks(pos, City, fontsize=10)
plt.xlabel(‘Happiness_Index’, fontsize=16)
___________ # Statement 3
__________ # Statement 4
___________ # Statement 5
Write the code to create a legend placed at the top right corner of the graph.
Choose the correct options from a -e.

a. Identify the suitable code to be used in the blank space in line marked as Statement 1.
i. matplotlib as plt iii. pandas as pd
ii. numpy as np iv. matplotlib.pyplot as plt
b. What is the name of the function to plot the required bar graph in the line marked as
Statement 2?
i. hist ( ) iii. bar ( )
ii. pie ( ) iv. scatter ( )
c. Fill in the blank in Statement 3 to set chart Title as “Happiness Index across cities by
gender” and font size as 18.
i. plt.xtitle(“Happiness Index across cities by gender”, fontsize =18)
ii. plt.title(“Happiness Index across cities by gender”, fontsize =18)
iii. plt.ytitle(“Happiness Index across cities by gender”, fontsize =18)
iv. plt.show (“Happiness Index across cities by gender”, fontsize =18)
d. identify the suitable code for line marked as Statement 4 to display the legends as shown
in the plot.
i. plt.showlegend( ) iii. plt.display( )
ii. plt.legend( ) iv. plt. show( )
e. fill in the blank marked in Statement 5 to display the plot.
i. plt.plot( ) iii. plt. display( )
ii. plt.showplot( ) iv. plt.show( )
7. What is the purpose of matplotlib library?
8. What is the purpose of a legend?
9. What is a histogram? What is its usage/utility?
10.What is the significance of data visualization?
11.Compare bar( ) and barh( ) functions.
12.What are the advantages of CSV file formats?
13.By default, read_csv( ) uses the values of first row as column headers in data frames.
Which argument will you give to ensure that the top/first row’s data is used as data and
not as column headers?
14.Which argument would you give to read_csv( ) if you only want to read top 10 rows of
data?
15.What all libraries do you require in order to bring data from CSV file into a dataframe?

You might also like