Pandas Practice Questions
Pandas Practice Questions
import numpy as np
d=np.array([10,20,30,40,50,60,70])
print(d[2:-2])
Q2. Name the method to find correlation between two arrays. Give syntax 1
Q3. ______ is the method used to horizontally stack an array over another array. 1
Q4. _______ attribute of the arange method is used to assign a data type to the array being 1
created.
Q5. Write the missing statement in the following code: 1
import numpy as np
arr1= np.arange(12)
ar = _________ # statement to reshape the above array to (3,4) size
print(ar)
Q6. Name the method used to group the data in a dataframe on the basis of one or more 1
column.
Q7. Write the output of the following questions: 2
import numpy as np
array1=np.array([10,12,14,16,18,20,22])
array2=np.array([10,12,15,16,12,20,12])
a=(np.where(array1==array2))
print(array2[a])
Q9. Rashmi wants to display the last three rows of the dataframedf and has written the 2
following code:
df.tail()
But last 5 rows are being displayed. Identify the error and rewrite the correct code so that
last 3
rows get displayed.
OR
Write the command to add a new column in the last placenamed “Salary” from the list
Sal=[40000,50000,60000] in an existing dataframe named EMP already having 2 columns.
print(Student[‘Age’].min() – Student[‘Age’].max())
print(Student.count())
Q14. What is the difference between sort_index() and sort_values() methods in pandas library? 2
Q15. Write a program plot two data sets on the same bar graph. First data set represents the 4
marks of Boys and second data set represents marks of girls in a class
Boy_mark=[34,67,87,90,34]
Girl_mark=[45,80,23,56,99]
Proper labels, title and legends should be given to the plot.
Q16. Create the following dataframe. Group the data on the basis of gender and find the name 4
of the boy who got maximum marks
Rollno Name Gender Marks
1 Nilansh M 480
2 Mili F 400
3 Josh M 450
4 Kumar M 240
5 Ishita F 305
6 Mitali F 398
7 Kevin M 401
Q17.W Write a program to check whether an array A can be vertically or horizontally stacked or both 4
on an
array B.
OR
Write a menu based program to perform four basic mathematical operations on two 1D numpy
arrays based on user’s choice.