0% found this document useful (0 votes)
52 views8 pages

Question Paper

Cs paper

Uploaded by

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

Question Paper

Cs paper

Uploaded by

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

Q. 1. What is DataFrame?

Q. 2. Write code to create empty DataFrame named ‘DF1’?

Q.3. Which method is used to create DataFrame in Python?

Q.4. Write two differences between Series and DataFrame.

Q.5. Create the following datafame using List of Dictionaries.

A B C

0 1 2 3

1 5 6 8

Pandas DataFrame

Q.6 . Which data types can be used to create DataFrame?

Q.7. Which library is to be imported to create dataframe Numpyndarrays?

Q.8. ----------------- methodin Pandas is used to change/modify the index of rows and coloums of

a DataFrame.

Q.9. Give an example to create dataframe form a single nadarray.

Q.10. Given an example to create dataframe form two ndarray.

Q.11. Write the output of the following code:

Import numpy as np
Import pandas as pd
A = np.array ([35,40,71,25])
B = np.rray ([27,34,56,73])
C = [11,22,33,44,]
DF + pd. DataFrame ([A,B,C,]) Print (DF)

Q. 12. Write the code in python to create dataframe form given list

L1 = [ “Anil” , “ Ruby” , “ Raman” , “Suman” ]


L2 = [35,56,48,85]

Q.13. Fill in the blank to produce the Output.


Import pandas as pd
L1 = [ “Anil” , “ Ruby” , “ Raman” , “Suman” ]
L2 = [35,56,48,85]
DF = pd. DataFrame ([L1, L2],
__________________________Print (DF)
Output
Ist IInd IIIrd IV
A Anil Ruby Raman Suman
B 35 56 48 85

Q.14. Aman store some data in the form of nested list. Later on he created datafframe “DF”
Form the list given below by writing the following code. How many columns will be there in “DF”
L1 = [ “ Aman “ , Cricket “ , “ 7th “ ],
[ “Ankit” , “ Hockey” , “ 11th ” ]
[ “Sunita” , “ Bastket ball ” , “ 9th ” ]
DF = pd. DataFrame (L1) Print (DF)

Q. 15. Which attribute of DataFrame is used to give user defined index value?
Q.16. Which attribute of DataFrame is used to give user defined column name?

Q.17. Complete the following code to get the Output given below:
Import pandas as
_________________________
L1 = [“Aman” , 45], [“Ankit” , 56], [“_____________”, 67]
DF = pd. ________________(L1,_____________= “Name”,
“Marks” ] ,index = [___________])Print (DF)
OUTPUT”
NAME MARKS
1 AMAN 45
2 ANKIT 56
3 SUNITA 67

Q.18. Complete the following code to get the Output given below:

Import pandas as
_________________________
L1 = [“Name” : [“Aman” , [“Aman” , “Ankit” , “Sunita “], “Mark” [45,56,67]
DF = pd. DataFrame(L1,Columns = [________________] , index = [1,2,3])
Print (DF)
OUTPUT”
MARKS NAME
1 AMAN 45
2 ANKIT 56
3 SUNITA 67

Q.19. Consider the code given below and answer the following question

Ld = [{‘a’ : 10, ‘b’ : 20} , {‘a’ :5, ‘b’ : 10, ‘c’ : 20}]
DF = pd. DataFrame (Ld)
Print (DF)
A. How many rows will be there in dataframe “DF”
B. How many columns will be there in dataframe “DF”
C. How many NaN will be there in dataframe “DF”
D. Write the missing import statement in the above code.
E. How many dictionaries are used in the above code.

Q.20. Given an example of creating dataframe form two series.

Q.21. Write five attributes of DataFrame.

Q.22. Which attributes of dataframe is used for the following .

1 To display row labels.


2. To display column labels.
3. To display data type of each column in the DataFrame.
4. To display all the values in the DataFrame.
5. To display number of rows and columns in a tuple.
6. To display total numbers of values in the dataframe.
7. To transpose the dataframe.
8. To returns the values True if DataFrame is empty and False otherwise.

Q.23. Name the function which is used to display first n rows in the DataFrame.

Q.24. Write a statement to display last 7 rows form dataframe “DF”

Q.25. Write a statement to display last 7 rows form dataframe “DF”

Q.26. There are 7 rows in a dataframe “DF”. How many rows will be displayed by the following
Statement? DF.head(10)

Q.27. What is the default value of ‘n’ tail (n) function?

Q28. Write a statement in python to add a new column “Marks” with values (23, 34, 45, 12) in a

Dataframe “DF”

Q.29. Consider the following dataframe “DF”

A B C

0 1 2 3

1 5 6 8

Pandas DataFrame

a. Write a statement to change values of column “C”. New values are (4,9)
b. Write a statement to change all the values of column “B” to 0
c. Write a statement to add a new row with value (7,8,9)
d. Write a statement that will return the result (2,3)
e. Write the output of the statement : DF. Size( )

Q.30. Fill in the blanks

Import pandas as pd
Import numpy as np
Name = ______________.array([ ‘Anil’, ‘Sumit’ , ‘ Ankit’ , ‘Ananya’])__________=
__________.DataFrame ( ) Print (DF)

Q.31. Write two methods of creating the following dataframe “DF”

Name Class

0 Anju 7

1 Suman 11

Pandas DataFraem

Q.32. Consider the above dataframe “DF” (Q.31) and write the code to add a new column “ Roll no”
With values (21 ,22)

Q.33. Consider the above dataframe “DF” (Q.31) and write the code to update the value of column “
“Roll no” , New values are (23 , 27)

Q.34. Consider the above dataframe “DF” (Q.31) and write the code to Change the values of columns
“Class” to “12”

Q.35. Consider the above dataframe “DF” (Q.31) and write the code to change the index values of
Both rows. Index value 0 and 1 should be replaced by “First” and “Second” respectively.

Q.36. Which function/method is used to add a new row in dataframe.

Q.37. Aman wants to add a new row with values (‘Suman” , 9 , 11) at the end of the dataframe “df”
He does not know the total number of rows available in dataframe. As a friends of Aman, help
Him to write the code.

Q.38. Which of the following code will change the value of entire row to “0” in dataframe “DF”
Code A : DF. Loc[ “preeti’ ] = 0
Code B : DF [ ‘preeti” ] = 0
Q.39. When we try to add a row with lesser values than the number of columns in the DataFrame,
It results in a ___________________error.

Q.40. When we try to add a column with lesser values than the number of row in the DataFrame,
It results n a _______________error.

Q.41. We can use the _____________________method to delete rows and columns form a
DataFraem.

Q.42. Write the code to delete the row with label ‘Book’ form dataframe “DF”

Q.43. Which parameter of drop ( ) function is used to specify the row or column to be delete?

Q.44. Write the code to delete the column with label ‘Marks’ form dataframe “DF”.

Q.45. Write the code to delete the column with label ‘Marks’ ‘Class’ and ‘Roll no’ from dataframe “DF”

Q.46. A) Raman wants to create a pandas dataframe form the data given below. He wants to give
Column name as “ Emp no “ and “Ename”. Help him to write the code.L1 = [1, “Anil”]
[2, Sunil”] , [3, “ Suman” ]
Q.46. B) Raman wants to display the column “ Emp no” fpr, dataframe “DF”. He writes the following
Code which is not working. Help him to correct the error.
Q.46.C) ‘Raman’ s friend Shreya ask him to add a new column “Salary” in dataframe “DF” with
Values ( 10000, 20000, 25000). Help him to write the code.

Q.46.D) What type of error is returned by the following statement written by Raman?
DF = DF.drop( “Sal” , axis = 1)
Q.46. F) Raman wants to change the row label 0,1,2, to “One” , “ Tow” , “ Three” respectively
Help him to write the code.
Q.47. Write two ways of indexing dataframe.

Q.48. Consider the pandas dataframe “DF” given below:


Emp Ename
One 1 Anil
Two 2 Sunil
Three 3 Suman
a. Print(DF.loc[“Two” ])
b. Print(DF.loc[ : , “Ename”])
c. Print(DF.loc[ “One” , “Two” ])
d. Print(DF.loc[[ “One” , “Two” ]])
e. Print(DF.loc[[ “One” , “Two” ]]
f. Print(DF[ “Emp no” , “Ename” ])
g. Print(DF[[ “Emp no” , “Ename”]])

Q.49. Consider the pandas dataframe “DF” given below:


Arnab Ramit
Samridhi Riya Mallika
Maths 90 92
89 81 94
Science 91 81
91 71 95
English 85 86
83 80 90
Hindi 97 96
88 67 99

Write the Out put of:


A. Print (DF.loc[ “MathsArnab” ] > 90)
B. Print (DF.loc[:, “Arnab”] > 90)
C. Print (DF.loc[ ‘ Maths’ : ‘ Science’])
D. Print (DF.loc[‘ Hindi’ : ‘English’ ])
E. Following two statemnts will produce the same result ?(yes/No)
1. Print(DF)
2. Print(DF.loc[ ‘Maths’ : ‘Hindi’])
F. Print(DF[[ ‘Arnab’ , ‘Ramit’ , ‘Riya’ ]])
G. Write a statement to display marks of “ Arnab” and “Ramit” of subjects “Maths”
‘Science’ and “English”.
H. Write the statement to display marks of “Arna;b” in “Maths”
I. Write the statement to display marks of “Riaya“ in all subjects
J. Write the statement display marks of Ramit, Samridhi and Riya of “English” subject.
K. Write the output of the following statement:
Print(DF.loc[[True, false, True, False]])
L. Write a statement to display the first record of pandas dataframe “DF”
M. Write a statement to display the last three records of pandas dataframe “DF”
N. Write the output of : print(DF.shape)
O. Write the output of : print(DF.ndlm)
P. Write a statement to get the following as output:

Maths Science English


Hindi 90 91 85
Arnab
97
Ramit 92 81 86
96
Samridhi 89 91 83
88
Riya 81 71 80
67
Mallika 94 95 90
99
Q. Write the output of : print(DF.size)
R. Write the output of : print(DF.empty)
S. Write the output of the following statement.
DF1 = DF. Loc[‘maths’ : ‘Science’ , [‘Arnab’ , ‘Samridhi’]]print(DF1 * 2)
T. Write the output of the following statement
DF1 = (DF.loc[‘Hindi’ : ‘Hindi’ , ‘Riya’ : ‘Riya’]) print(DF1% 2)
U. Write the code to find the highest marks in subject “Hindi”
V. Write the code to find the lowest marks in subjects “English”
W. Write the output of the statement : print(min(DF)
X. Write the output of the following code:
DF1 = DF.loc[‘Enghlish’ : ‘Hindi’]
DF2 = DF.loc[‘English’ : ‘Hindi’]
Y. Write the output of the following:
DF1 = DF.loc[‘English’ : ‘Hindi’]
DF2 = DF.loc[‘Maths’ : ‘Science’]
DF1 = DF1.append(DF2)print(DF)
Z. Write the output of the following :
DF1 = DF.loc[‘English’ : ‘Hindi’]
DF2 = DF.loc[‘Maths’ : ‘Science’]
DF1 = DF1.append(DF2, sort = “True”) print(DF)

Q.50. Which function in pandas dataframe is used to insert a new column at specific position?

Q.51. Name two functions/statement which are used to delete column form pandas dataframe?
Q. 53. Consider the pandas dataframe “DF” given below:
Arnab Ramit
Samridhi Riya Mallika
Maths 90 82
89 81 94
Science 91 81
91 71 95
English 85 86
83 80 90
Hindi 97 96
88 67 99

a. Write the code to insert column “Amit” with (90, 8, 92, 959) at position 5 (after Malllika )
b. Write the code to insert column “Amit” with values ( 92, 92, 95, 89) a position 2.
c. Write the code to delete column “Riya” form dataframe “DF”
d. Write the code to delete columns “Ramit” and “Riya” form dataframe “DF”
e. Following two statements will give same or different result.
Pint(DF.loc[0 : 1])
Print(DF.loc[“Maths” : “Maths”])
f. Write the statement to display marks of “Amit” in “Maths”.
g. Aman has written the following command to delete the column “Amit” form dataframe
“DF”. Output is not coming . Help him to correct the code.
DF.drop(“Amit”)print(DF)
h. Write a program to write dataframe “DF” to “Data.csv”
Q.54. Impot pandas as pd
A. = {‘Sunil’ : 28, ‘Raman’ : 20, ‘Kamal’ : 19, ‘Ashu’ : 26}
B. = {‘Kamal’ : 34, ‘Ram’ : =33, ‘ Parth’ : 38, ‘Ashu’ : 20}
Table = {‘Sem – l’ : A, ‘Sem-II’ : B}
Df = pd.DataFrame(table)
Print(df.loc[‘Kamal’ : Ram’]) print(df)
Q.55. Write a Python code to create a DataFrame with appropriate column headings form the list given
below: [1, ‘Anil’ , ‘X’ ], ] [2, ‘Sunil’ , ‘XI’ ],
[3, ‘Ravi’ , ‘X’ ] , [4, ‘Ashu’ , ‘XI’]]
df = pd.DataFrame(L, columns=[‘Ralno’ , ‘Name’, Class’ ])print(df)
Q56. Consider the given DataFrame ‘Stocks’ :
Name price Quantity
0 Ram 890 10
1 Register 395 12
2 Keyborad 350 5
3 Mouse 250 17
Write suitable Python statements for the following:
1. Add a column calld ‘Total’ which is product of price and Quantity
2. Add a new item named “ Scanner” having price 3250 and Quantity as 10.
3. Remove the column Quantity
Q.57. Dhiriti is working in a company where she was asked to create the following dataframe. Help her
Writing the code to create the dataframe ‘df’ with ‘W! , ‘W2’ , ‘W3’ , ‘W4’ Index value and also
Write the answer of he following task.
Wing Desktop Labtop Table
W1 Pre-Primary 15 5 2
W2 Primary 22 10 3
W3 Middle 18 8 4
W4 Senior 30 15 7

1. Predict the output of : print(df.shape)


2. Write Python statement to display the value of column ‘Laptop’ and ‘Tablet’ of indexes W3
and W4.
3. Add a new row in dataframe ‘df’ With index ‘W5’ and values are [ ‘Secondary’ , 20,15, 8)
4. Write the output of : print(df.size)
5. Write a Statement in Python to delete rowof ‘W3’.
6. Write the output of : print(df.T)
Q.58. Consider the following DataFrame ‘DF’ and answer the flowing question
Wing Desktop Labtop Table
W1 Pre-Primary 15 5 2
W2 Primary 22 10 3
W3 Middle 18 8 4
W4 Secondary 20 15 8
W5 Senior 30 15 7

1. Write a Python statement to prin number of Desktop and Tablet in Middle and Secondary
Wing.
2. Write a Python statement to print Wing which hve ‘ Desktop’ more than 20.
3. Write a Python statement to print Wing and numbr of Laptop which have ‘Desktop’ more
than 20
Q. 59. Read the following code:
Import pandas as pd
L = [[‘Pre-Primary’, 15, 5, 2], [‘Primary’ , 22,10,3], [Middle’ , 18,8,4], [‘Senior’ , 30,15,7]
Df = [d. DataFrame,(L, columns = ‘Tablet’])print(df)
Answer the question given below:
1. What is the shape of the dataframe df?
2. Name the index and column names off dtaframe df
3. Write a statement in pythonto add index value as [‘W1’ , ‘W2’ , ‘W3’ , ‘W4’ , ‘W5’ , ]
4. Write a Python statement to calculate Laptop + Desktop + Tablet and display it as ‘Total
Systems’ in a dataframe.
5. Write the output of the following statements
Print(df) Print(“_________________________________”)
Print(df.loc[ ;, ‘Desktop’])print(“_________________________________”)
Print(df.loc[: , ‘Desktop’ , : ‘Laptop’])print(“________________________”)
Print(df.iloc[1:, 3,0 : 2])print(“___________________________________”)
Print(df.iloc[0:1, 1: 2])print(“____________________________________”)
Print(df[1 : 3])print(“____________________________________”)
Q.60. Consider the following code and answer the following.
Import pandas as pd
D1 = {‘C1 : ‘UK’ ,C2’ : ‘USSR’, ‘C3’ : ‘USA’}
D2 = (‘S1’ : ‘UP’ , ‘S2’ : ‘Delhi’}
City = {1 : D1, 2 : D2}
Df = pd.DataFrame(city)print(df)

1. Write the output of the above code


2. Write the index value of above dataframe ‘df’
3. Wite the column names of above dataframe ‘df’
1.
1 2
C1 UK NaN
C2 USSR NaN
C3 USA NaN
S1 NaN UP
S2 NaN Delhi
2.
[‘C1’,’C2’, ‘C3’, ‘S1’, ‘S2’] or you can also write (‘C1’ , ‘C’2 , ‘C3’, S1,S2)

3 [1,2] OR Simply Write – 1,2


.

Q.61. Consider the following datarame ‘df’


Name price
P1 Pen 10
P2 pencil 5
P3 sharpner 3
Write suitable Python statements for the following:
1. Create the above dataframe in Python
2. Add one more item named ‘rabber’ with price = 5 and index ‘p4’
3. Add one column named ‘Quantity’ with values = [5 ,9 ,4, 6]
4. Add one more column named ‘Total Price’ which can be calculated ‘ Name’ * ‘Price’
5. Write a statement to display ‘price’ and ‘Quantity’ column of index ‘P2’
6. Write a statement to display the detail of ‘p2’ and ‘P3’
7. Remove the column ‘Quantity.

Q.62. Observe the following code.


Import pandas as pd
L = [{‘M’: 7, ‘N’ : ‘O’ : 5}, {‘M’ : 7, ‘O’ : 15, ‘N’ : 10, ‘P’ : 23}
df = pd. DataFrame (L)
Write the output of the following :
1. Print(df)
2. List the index of the DataFrame df

You might also like