Series
Series
0 0.430271
1 0.617328
2 -0.265421
3 -0.836113
0 43.0271
1 61.7328
2 -26.5421
3 -83.6113
(b) S > 0
0 True
1 True
2 False
3 False
1
Page
(c) S1 = pd.Series(S)
>> Create a same series
0 0.430271
1 0.617328
2 -0.265421
3 -0.836113
(d) S3 = pd.Series(S1) + 3
0 3.430271
1 3.617328
2 2.734579
3 2.163887
2. Consider the same Series object, S given in the previous question. What
output will be produced by following code fragment?
print(S)
print(S[‘AMZN’])
S[‘AMZN’] = 1.5
print(S[‘AMZN’])
print(S)
print(S)
AMZN 0.430271
AAPL 0.617328
MSFT -0.265421
2
Page
GOOG -0.836113
print(S[‘AMZN’] => 0.430271
print(S)
AMZN 1.5
AAPL 0.617328
MSFT -0.265421
GOOG -0.836113
print(S + S2)
S = S + S2
print(S + S2)
Ans:
print(S + S2)
=>Output-1
pencils 37
notebooks 46
3
scales 83
Page
erasers 42
S = S + S2
print(S + S2)
=>Output-2
pencils 54
notebooks 59
scales 114
erasers 74
4. What will be the output produced by following code, considering the Series
object S given above?
(c) print(S[0:2])
(d) S[0:2] = 12
print(S)
(e) print(S.index)
(f) print(S.values)
Ans : Output
(b) 0 0.430271
(c) 0 0.430271
1 0.617328
(d) 0 12
4
Page
1 12
2 -0.265421
3 -0.836113
print(S2.index)
S2.index = [0, 1, 2, 3, 4, 5]
S2[5] = 250
print(S2)
Ans:
(d) NO ERROR
5
Ans: data = np.array([‘a’, ‘b’, ‘c’, ‘d’, ‘e’, ‘f’ ] ) => missing of ‘)’
Ans :
Mismatch of number of values and indices, values are 5 but indices are 4 only.
Ans:
9. If Ser is a Series type object having 30 values, then how are statements (a),
(b) and (c), (d) similar and different.
(a) print(Ser.head( ))
(a) print(Ser.head( ))
Similarities => head( ) print top rows, while tail() print bottom rows
Difference=> haed( ) and tail() print only 5 top or bottom rows respectively
head(n) and tail(n) prints ‘n’ top rows or bottom rows respectively
10. What advantages does DataFrame offer over Series data structure? If you
have similar data stored in multiple series and a single dataframe, which one
would you prefer and why?
If we have to store the similar data in Multiple Series and DataFrame, I prefer
DataFrame, because
11. Given :
import pandas as pd
df = pd.DataFrame(d)
Page
df1 = pd.DataFrame ( d, index = [‘d’, ‘b’, ‘a’ ] )
print(df)
print(df1)
print(df2)
What will Python show the result as if you execute above code?
one two
a 1.0 1.0
b 2.0 2.0
c 3.0 3.0
d NaN 4.0
Output of print(df1)
one two
d NaN 4.0
b 2.0 2.0
a 1.0 1.0
Output of print(d2)
two three
d 4.0 NaN
a 1.0 NaN
(a) display only column ‘a’ from dataframes df, dfl, and df2.
(b) display only rows 0 and 1 from dataframes df, dfl, and df2.
8
Page
(c) display only column ‘a’ and ‘b’ for rows 1 and 2 from dataframes df, dfl and
df2.
Answer: (a) display only column ‘a’ from dataframes df, dfl, and df2.
Note : There is no column named ‘a’ in dataframes df, df1 and df2. If we have to
access row ‘a’ then
>>> df[‘a’]
>>> df1[‘a’]
>>> df2[0:1]
Answer: (b) display only rows 0 and 1 from dataframes df, dfl, and df2.
>>> df[0:2]
“weight” : (75,123,239),
13. Predict the output of following code (it uses above given dictionary my_di)
df = pd.DataFrame(my_di)
print(df)
Ans:
0 Jiya 10 75 4.5 1 M
Page
1 Tim 15 123 5.0 1 M
14. Consider the same dictionary my_di in the previous question, what will be
the output produced by following code ?
print(df2)
Ans:
Using the df2 created in Question 14, answer the outputs of questions (15 to 19)
given below.
15. Assume that required libraries (panda and numpy) are imported and
dataframe df2 has been created as per questions 13 and 14 above. Predict the
output of following code fragment
Ans:
Jiya 75
Tim 123
Rohan 239
Output of : print(df2.weight[‘Tim’])
10
123
Page
16. Assume that required libraries (panda and numpy) are imported and
dataframe df2 has been created as per questions 13 and 14 above. Predict the
output of following code fragment:
df2[“Married”] = False
print ( df2 )
Ans:
# Add a New Column “IQ” with different value for each row
df2[“Married”] = False
print ( df2 )
Output:
1. Assume that required libraries (panda and numpy) are imported and
dataframe df2 has been created as per questions 13 and 14 above.
Predict the output produced by following code fragment:
print ( df2 )
print(df2.loc[“Jiya”]) #(a)
print(df2.loc[“Jiya”,”IQ”]) #(b)
print(df2.iloc[0]) #(d)
print(df2.iloc[0,5]) #(e)
Ans:
#(a) print(df2.loc[“Jiya”])
name Jiya
age 10
weight 75
height 4.5
siblings 1
gender M
IQ 130
Married False
College NaN
#(b) print(df2.loc[“Jiya”,”IQ”])
130
IQ Married College
Page
Jiya 130 False NaN
#(d) print(df2.iloc[0])
name Jiya
age 10
weight 75
height 4.5
siblings 1
gender M
IQ 130
Married False
College NaN
#(e) print(df2.iloc[0,5])
gender IQ Married
df = pd.DataFrame(d)
print(df)
Page
print( “New DataFrame :”)
Answer : Output
Original DataFrame
0 1 6 9
1 4 7 0
2 3 8 1
New DataFrame
0 1 6 9
print( ” Before” )
print(df1)
print( ‘After’)
print(df1)
Answer: Output
Before
age name
1 20 Ruhi
14
Page
2 23 All
3 22 Sam
After
1 20 Ruhi BA
2 23 All BE
3 22 Sam MBA
1 Sunil Pillai 90 80
2 Gaurav Sharma 65 45
3 Piyush Goel 70 90
4 Kartik Thakur 80 76
(i) Add both the scores of a batsman and assign to column “Total”
(ii) Display the highest score in both Score1 and Score2 of the DataFrame.
Or
15
print(batsman[‘Score2’].max())
(iii) print(batsman)
22. Consider the following dataframe, and answer the questions given below:
(i) Write the code to find mean value from above DataFrame df over the index and
column axis.
(ii) Use sum() function to find the sum of all the values over the index axis.
or
df.mean(axis=’index’)
or
df.mean(axis=0)
Output:
Quarter1 5080.0
Quarter2 3920.0
Quarter3 8080.0
Quarter4 2960.0
dtype: float64
df.mean(axis=’columns’) or df.mean(axis = 1)
16
Page
0 7300.0
1 2950.0
2 4775.0
3 3250.0
4 6775.0
dtype: float64
Output:
Quarter1 25400
Quarter2 19600
Quarter3 40400
Quarter4 14800
dtype: int64
>>> df
‘Quarter3′:’Qtr3′,’Quarter4′:’Qtr4’}, axis=1)
Page
Quarter1 Quarter2 Quarter3 Quarter4
No, We can’t use the mapper and columns parameter together in a rename()
method. It will raise an error message:
24. Find the error in the following code? Suggest the solution.
>>> topDf
del topDF[‘ColumnName’]
25. Find the error in the following code considering the same dataframe topDf
given in previous
(b) topDf.rename(columns={})
18
Ans :
Page
(a) rename() method need a name-dictionary value for index and columns
arguments. In this statement value is given as list, that is wrong. We can write it in
this way –
Post navigation
← Previous Post
Next Post →
Related Posts
20
Page
Class 12 IP 065 Ch 1 Python Pandas I Type A
Very Short Questions Answer
Sumita Arora Solution Class 12 Informatics Practices / By asacademy
21
Page
Class 12 IP 065 Ch 1 Python Pandas 1 Type C
Long Answer Questions
Sumita Arora Solution Class 12 Informatics Practices / By asacademy
22
Page
Class 12 IP 065 Ch 2 Python Pandas II Type A
Very Short Sumita Arora Book Questions
Answer
Sumita Arora Solution Class 12 Informatics Practices / By asacademy
23
Page
Class 12 IP 065 Ch 5 MySQL Revision Tour
Check Point Questions Answer
Sumita Arora Solution Class 12 Informatics Practices / By asacademy
24
Page
Class 12 IP 065 Chapter 9 Introduction to
Computer Networks Sumita Arora Solution
Sumita Arora Solution Class 12 Informatics Practices / By asacademy
25
Page
Class 12 IP 065 Chapter 9 Introduction to
Computer Networks Assignments Sumita
Arora Solution
Sumita Arora Solution Class 12 Informatics Practices / By asacademy
Recent Posts
Page
Python Program to accept three integers and print the largest of the three
using if only
Python Program to enter two numbers and perform all arithmetic calculator
Solution
Arora Solution
Solution
Archives
29
Page
thanks for visiting
WWW.MYCSTUTORIAL.IN
Question Answers
Class IX Computer Application (165)
Class X Computer Application (165)
Class IX Info. Tech. (402)
Class X Info. Tech. (402)
Class XI Computer Science (083)
Class XII Computer Science (083)
Class XI Informatics Practices (065)
Class XII Informatics Practices (065)
30
Important Links
Page
CBSE 9 to 12 Syllabus
CBSE 9 to 12 SQPs
NCERT Books
NCERT Solution
ICSE 9 to 12 Syllabus
ICSE 9 to 12 SQPs
Get in Touch
Contact for Online Tution :
+91 – 95 41 – 8 4 – 7706
info@anjeevsinghacademy.com
anjeevsinghacademy@gmail.com
Sorry! You cannot copy content of this page. Please contact, in case you want this
content.
Scroll to Top
×
Chapter 1 : Python Pandas – I
Sumita Arora Book Exercise Solution of Class 12 Informatics Practices
[065]
Type B – Short Questions Answers
Class 12 Informatics Practices [065] – Sumita Arora Book Exercise Solution
Sumita Arora Solution