C12_Worksheet 2_IP_2024-25

Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

Worksheet II Session 2024-25

Class XII - Informatics Practices


Q1 Objective type questions :-
A. Name any 4 data types which can be used for creating a Series.
B. Which of the following is the correct statement for creating a series to assign blank / Null to all 5 elements
of the series?
i. s = pd.Series() iii. s = pd.Series(NaN,index=[1,2,3,4,5])
ii. s = pd.Series(NaN,5) iv. s = pd.Series(NaN*5)
C. Which of the following is the correct statement to create a series of multiple tables of 5?
i. s = pd.Series(range(5,51,5)) iii. s = pd.Series(range(5,5*11))
ii. s = pd.Series(range(5,5,5)) iv. All of these
D. Pandas series is a combination of________
i. Records arranged in row and column iii. Collection of 1 dimensional data and associated index
ii. Collection of 2 dimensional data iv. All of the above
E. Data Type can be specified as int16 for a Series object, by using :
i. pd.Series(data = array, dtype = int16) iii. pd.Series(data = array, dtype = numpy.int16)
ii. pd.Series(data = array.dtype = pandas.int16) iv. None of the above
F. When we create DataFrame from List of Dictionaries, then number of columns in DataFrame is equal to
the _______
i. maximum number of keys in first dictionary of the list
ii. maximum number of different keys in all dictionaries of the list
iii. maximum number of dictionaries in the list
iv. None of the above
G. To get the top 5 rows of a series, you may use the _______________ function.
H. A Dataframe object is size mutable (True / False)
I. If data is an ndarray, index must be the same length as data. (True /False)
J. Series is a one-dimensional labeled array capable of holding multiple data type.(True /False)
Q2. Write the command to create the given Series and then double the value in series and store in another series
named Series2
A 100
B 200
C 300
D 400
E 500
Q3. Consider the following Series object, SResult
English 99
IP 95
Physics 92
Accountancy 94
Chemistry 92
History 100
Math 96
i. Write the Python code which will display only IP.
ii. Write the Python code to increase marks of all subjects by 10.
Iii. Write the Python code to only the last 2 values
Iv. Write the Python code which will display the name of the subjects having score>=95.
v. Write the Python code to name the series as SMaxResult
vi. Create a Dataframe using this Object SResult.
vii. Add a new column containing the Term II marks in all the subjects.
Viii. Write the Python code select the rows where the marks in term I exam is greater than 95%.
IX Display the size of the dataframe.
Q4. Complete the code by filling in the blanks

a list1 = [2, 4, 5, 6, 9] b List1 = [2, 4, 5, 6, 9]


s1 = pd.Series(___________) ____ = pd.Series(given_list,____ = [1, 3, 5, 7, 9])
print(_____) print(seriess)

c dict={'name':['Win1', 'Win2','Win3'],
'age' : [22, 25, 24],
'occ' : ['engineer', 'doctor', 'accountant']}
DF = pd.DataFrame(_______)
print(_______)

Q5. Write the output for the given block of code

a import pandas as pd b import pandas as pd


import numpy as np import numpy as np
s = pd.Series(np.arange(10,50,10)) data = {'one':'a','two':'b','three':'c'}
print(s) s=pd.Series(data)
print (s.ndim) print(s)
print(s.shape) print(s.size)
print(len(s))

c import pandas as pd d Df = pd.DataFrame({


import numpy as np 'c1': ['P', 'Q', 'R', ‘S’,np.nan, 'D'],
x=np.arange(10,15) 'c2': [30, 100, 39, 28, 27, 54],
s3=pd.Series(index=x, data=x*2) 'c3': [110, 111, 191, 134, 152, 130],
s4=pd.Series(x**2,x) 'c4': ['a', 'B', 'c', 'D', 'e', 'F']})
print(s3) print(Df.sort_values(by=['c1']))
print(s4)

e df = pd.DataFrame(index=['a', 'b', 'c'], f import pandas as pd


columns=['Name1', 'Name2', 'name3']) df = pd.DataFrame
print("use of loc[ ] & iloc[ ]") (np.random.randn(5,3), columns=
print(df.loc['a']) ['A','B','C'])
print(df.iloc[0]) print(df)
print(df.loc['b':'date']) if df.empty:
print(df.iloc[0]) print('DataFrame is empty!')
print(df.iloc[-5:])
print(df.iloc[:, 2])
print(df.iloc[:3, :3])

g import pandas as pd h df = pd.DataFrame(index=['a', 'b', 'c'],


df = pd.DataFrame({'c1': [10, 11, 12], 'c2': columns=['Name1', 'Name2', 'name3'])
[100, 110, 120]}) dataframe_sorted = df.sort_index()
for index, row in df.iterrows(): print(“dataframe_sorted”)
print(row['c1'], row['c2'])
print(df['c1'].idxmax())
print(df.idxmin())

i df = pd.DataFrame({
'col1': ['A', 'A', 'B', ‘Z’, 'D', 'C'],
'col2': [2, 1, 9, 8, 7, 4],
'col3': [0, 1, 9, 4, 2, 3],
'col4': ['a', 'B', 'c', 'D', 'e', 'F'] })
print(df.sort_values(by=['col1']))

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy