Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

Sarvodaya Public School

Azamgarh
Time : 45 mins. Class Test-1 (XII IP) M.M. 10

Section –A
Q1. What is NumPy Array?
Ans: A NumPy array is simply a grid that contains values of the same/homogenous type. NumPy Arrays come in two
forms:
∑ 1-D(one dimensional) arrays known as Vectors(having single row/column only)
∑ Multidimensional arrays known as Matrices(can have multiple rows and columns)
Example 1D array Example 2D array
import numpy as np import numpy as np
list = [1,2,3,4] a1 = np.array([ [10,11,12,13] , [21,22,23,24] ])
a1=np.array(list)

Q2. What function is used to create numpy 1-D array ?


Ans: Function to create numpy array np.array()
Q3.Predict the output of the following code fragments. Assume library Numpy has been imported as np: (1)
(i) x=np.array([1,2,3]) y=np.array([3,2,1])
z=np.concatenate([x,y])
print(z)

Ans: output : [1 2 3 3 2 1]

Section –B
Q1-What do you understand by reshaping of a dataframe . Also ,name the methods which are used to do so.

Ans: Reshaping : changing the rows and columns, column and index labels along with the values.
pivot() and pivot_table()

Q2-State the difference between reindexing and renaming lables in a dataframe.Give examples.

Ans: Reindexing : Changing the order of rows in a dataframe. Example with reindex()
Renaming : Only changing the names of the existing index labels. Example with rename()

Q3-Write the python code to plot the given histogram with the following dataset:

(1)

(1)
(2)

(2)
Sarvodaya Public School
Azamgarh

Ans: import matplotlib.pyplot as plt


Score=[8,10,15,25,28,35,47,49,50,63,67,53,57,58,69]
plt.title(“Score Tally”)
plt.xlabel(“Score Interval”)
plt.ylabel(“No of Players”)
plt.hist(Score,bins=[0,10,20,30,40,50,60,70],edgecolor=”blue”, facecolor=”blue”)
plt.show()

(3)

Ans: import numpy as np


import pandas as pd
from collections import OrderedDict

table = OrderedDict((
("Product Name", ['Mixer','Dish Washer', 'Egg Beater', 'Mixer','Dish Washer']),
('Company',['Bajaj', 'Philips', 'Bajaj', 'Sony','Philips']),
('Price', [2000,6000,500,2500,6500])))
df1=pd.DataFrame(table)
print(df1)
p = df1.pivot_table(index='Company',columns='Product Name', values='Price')
print("\n\nDATA OF PIVOT")
print(p)

You might also like