Numpy QP
Numpy QP
Numpy QP
6 Find errors in the following code (if any) and correct the code by rewriting it and underlining the 2
corrections :
x = int ("Enter value for x : "))
for in range [0,11]:
if x = y
print x+y
else:
Print x-y
7 Write a Python program to combine two dictionaries by adding values for common keys : 2
d1={'a':100, 'b':200, 'c':300}
d2={'a':300, 'b':300, 'd':600}
The output dictionary should look like this sample :
NewDict={'a':400, 'b':500, 'c':300, 'd':600}
10 Create a dictionary whose keys are month names and whose values are the number of days in the 3
corresponding months.
a) Ask the user to enter a month name and use the dictionary to tell them how many days are in the
asked month
b) Print out all the months with 31 days
12 Create an ndarray with values ranging from 10 to 49 each spaced with a difference of 3. 1
13 What functions can you use for joining two or more ndarrays ? 1
16 Consider the ndarray Ary1 given in Question 15, what will be the output produced by the following array 2
slices ?
a) Ary1[ : 3, ::2]
b) Ary1[::-1, ::-1]
18 Write the process and syntax of joining NumPy arrays along with an example for each of : 3
hstack( ), vstack( ) and concatenate( )
22 Write down the syntax to select/access a subset from a DataFrame using Row/Column name. 1
25 Write code statements to address the following, from a DataFrame namely sales : 2
a) Print only columns ‘Item’ and ‘Revenue’
b) Print the value of cell in 5th row, ‘Item’ column
26 Write the code to create an ndarray having 6 zeros in it. Write statement to change 3rd and 5th element 2
of this ndarray to 15 and 25 respectively.
27 Write a Pandas program to create and display a DataFrame from specified dictionary data which has the 3
index labels.
exam_data = {'name': ['Anastasia', 'Dima', 'Katherine', 'James', 'Emily', 'Michael', 'Matthew', 'Laura',
'Kevin', 'Jonas'], 'score': [12.5, 9, 16.5, np.nan, 9, 20, 14.5, np.nan, 8, 19], 'attempts': [1, 3, 2, 3, 2, 3, 1,
1, 2, 1], 'qualify': ['yes', 'no', 'yes', 'no', 'no', 'yes', 'yes', 'no', 'no', 'yes']}
labels = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j']
Also count and print the number of rows and columns in the program.
28 In the given DataFrame exam_data as mentioned in Question 27, Write down the code snippet to do the 3
following :
a) To insert a new column in the given DataFrame
b) To change the order of given DataFrame Columns
c) To select a row of the given DataFrame by providing an integer index
***