0% found this document useful (0 votes)
48 views5 pages

DataFrame Revision

Class 12 dataframe revision question pdf

Uploaded by

shreyanshi1718
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
48 views5 pages

DataFrame Revision

Class 12 dataframe revision question pdf

Uploaded by

shreyanshi1718
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

REVISION

DataFrame
1. What will be the output of the Python program men oned below ?
import pandas as pd
df=pd.DataFrame(['Apple','Banana','Orange','Grapes','Guava'])
print(df[2:4:2])
2. A Dataframe object is value mutable.
3. Which of the following func on is used to create DataFrame?
4. We can add a new row to a DataFrame using the _____________ method
5. Which of the following is used to give user defined column index in DataFrame?
6. When we create DataFrame from List of Dic onaries, then number of columns in
DataFrame is equal to the _______
7. The following code create a dataframe named ‘D1’ with ___________ columns.
import pandas as pd
dicts = [{‘a’:10, ‘b’:20}, {‘a’:5, ‘b’:10, ‘c’:20}]
D1 = pd.DataFrame(dicts)
8. The following code create a dataframe named ‘D1’ with _______________ columns.
import pandas as pd
D1 = pd.DataFrame([1,2,3] )
9. The following code create a dataframe named ‘D1’ with ______ rows.
import pandas as pd
LoD = [{'a':10, 'b':20}, {'a':5, 'b':10, 'c':20}]
D1 = pd.DataFrame(LoD)
10.In DataFrame, by default new column added as the _____________ column
11.When we create DataFrame from List of Dic onaries, then dic onary keys will become.
12. Which of the following statements is false?
(a) Dataframe is size mutable
(b) Dataframe is value mutable
(c) Dataframe is immutable
(d) Dataframe is capable of holding mul ple type of data

13. In the following statement, if column ‘Rollno’ already exists in the DataFrame ‘D1’ then
the assignment statement will __________
D1['Rollno'] = [1,2,3] #There are only three rows in DataFrame D1

14. NaN stands for__________


15. Write statement to transpose dataframe DF.

16. In given code dataframe ‘D1’ has _____ rows and ______ columns.
import pandas as pd
LoD = {“Name” : [“Amit”, “Anil”,”Ravi”], “RollNo” : [1,2,3]}
D1 = pd.DataFrame(LoD)

17. Name the func on that returns number of non-NaN values of dataframe ?

18 In DataFrame, axis 0 is for______

19. D1[ : ] = 77 , will set __________ values of a Data Frame ‘D1’ to 77.

20. Display first row of dataframe ‘DF’.


21.To display the 3rd, 4th and 5th columns from the 6th to 9th rows of a dataframe DF; you can
write _____.

22. To delete a column from a DataFrame, you may use _____ statement.(drop is a method del is statement)

23.

24. Write a statement to append the DataFrame ‘DF2’ to the DataFrame ‘DF’

25. Write a statement to display the sales made by all sales persons in the year 2017.

26. Write a statement to add new column for another year ‘2018’ with values 55000, 65000, 75000, 85000, 95000
(a) DF[2018] = 55000, 65000, 75000, 85000, 95000
(b) DF[2018] = [55000, 65000, 75000, 85000, 95000]
(c) DF[2018] = (55000, 65000, 75000, 85000, 95000)
(d) All of the above

27. Write a statement to add new row for ‘Raman’ with values 55000, 66000, 77000, 88000
(a) DF.loc[‘Raman’] = 55000, 66000, 77000, 88000
(b) DF.loc[‘Raman’] = [55000, 66000, 77000, 88000]
(c) Both of the above
(d) None of the above

28. Raman was caught in the case of chea ng so his Boss decided to set his sales of all years to 0(Zero). Help him to write
the code for same.
(a) DF.loc[‘Raman’] = {0} (b) DF.loc[‘Raman’] = [0] (c) DF.loc[‘Raman’] = 0 (d) All of the above
29. Write a statement to delete a column having column label as 2017.
30. Write a statement to delete two columns having column label as 2017 and 2016.
31. Replace the column label from 2016 to 2020.
32. Consider the DataFrame ‘DF’ given below and answer the ques ons from Q to Q.
Following DataFrame ‘DF’ containing marks of five students in three subjects.

33. Display the marks of Harry in Maths Subject.

34. Display the marks of Karan in all Subjects.


(a) print(DF.loc[‘Science’ : ‘English’, ‘Karan’]) (b) print(DF[‘Karan’])
(c) Both of the above (d) None of the above
35. Display marks of Karan and Rounaq in Maths and Science
36. Write a statement to check that in which subject Kiran scored more than 90.
37. Write a statement to rename the subject ‘Maths’ to ‘Mathema cs’
38. Write a statement to remove column labelled as ‘Harry’
39. Write a statement to increase five marks of all students in all subjects.
40. Write a statement to increase marks of ‘Anuj’ in ‘Maths’ Subject by 10.
41. Which of the following statement will import Pandas library?
(a) import pandas as pd (b) import pandas as py (c) import pandas as ps (d) All of these
42.

43.
44. Mr. Ankit wants to change the index of the Data Frame and the output for the same is given
below. Iden fy the correct statement to change the index

45. He wants to arrange records of all the passenger’s year wise in descending order.
(a) df.sort_values(by=’Year’, ascending=True, inplace =False)
(b) df.sort_values(by=’Year’, ascending=False, inplace =False)
(c) df.sort_values(by='Year', ascending=False, inplace =True)
(d) df.sort_values(by=’Year’, descending=True, inplace =True)
46.

47. Write down the command that will give output:


rollno 6
name TanishGoel
UT1 24
UT2 24
UT3 24
UT4 24
(a) print(df.max) (b) print(df.max()) (c) print(df.max(axis=1)) (d) print(df.max, axis=1)
48. The teacher needs to know the marks scored by the student with roll number 4. Help her
to iden fy the correct set of statement/s from the given op ons
(a) df1=df[df[‘rollno’]==4]
print(df1)
(b) df1=df[rollno==4]
print(df1)
(c) df1=df[df.rollno=4]
print(df1)
(d) df1=df[df.rollno==4]
print(df1)
49. Which of the following statement/s will give the exact number of values in each column
of the dataframe?
(i) print(df.count())
(ii) print(df.count(0))
(iii) print(df.count)
(iv) print(df.count(axis=’index’))
50.

51. For the above created Dataframe df in Q.50 write single line statements for each of the
following parts (a) to (c), which use Pandas method:
a. To display the 'Names' and 'Marks' columns from the DataFrame.
b. To change the 'Marks' in the 4th row (i.e. for index 3) to 91.5
c. To display the rows where number of 'Trials' in the examina on is less than 2 and
'Marks' is greater than 95

52. Consider the following DataFarme df and answer ques ons from (i) to (v) :

i) Write down the command that will give the following output :
rollno 2
Name Pranshu
Age 14
Marks 60.9
Class 12B
Name: 20, dtype: object
ii) The teacher wants to know the highest marks secured by the students. Which statement would help her to get the
correct answer ?
iii) Which of the following statement(s) will add new column ‘fee’ as third column with values
[3200,3400,4500,3100,3200,4000] in DataFrame df ?
iv) Which of the following commands is useds to remove the column ‘Age’ in the DataFrame df?

v) Which of the following command would rename the DataFrame df ?


(A) df.rename(['marks','Term1'], inplace=True)
(B) df.rename({'marks':'Term1'}, inplace=True)
(C) df.rename(columns={'marks':'Term1'}, inplace=True)
(D) df.rename(['marks':'Term1'], inplace=True)
53. Write a program in Python to create the series of all the alphabets of ''Happy'' with
default index. Print the first three alphabets.

54. Consider the following two series ‘A’ and ‘B’ :


A=pd.Series([2,4,6], index=[0,1,2])
B=pd.Series([1,3,5], index=[1,2,3])
i) Write the statement to add both the series ‘A’ and ‘B’.

ii) Write the statement to mul ply two series ‘A’ and ‘B’.

You might also like