Font size
Worksheetsclass 12_dataframes_1
Total questions: 35
Worksheet time: 18mins
Best way to import the pandas module in your program ?
1.import pandas
2.import pandas as pd
3.from pandas import *
4.All of the above
we can analyze the data in pandas with :
Series
Dataframe
Both
none
DataFrame is .......................
size mutable, data mutable
size immutable, data mutable
An empty DataFrame can be created by.................
passing arguments
without passing arguments
Which of the functions can be used to delete column/row from a DataFrame?
pop()
at()
drop()
iloc()
Dataframe can contain multiple series
True
False
DataFrame in pandas is
1. dimensional array
2. dimensional array
3.dimensional array
4.None of the above
Not a function of Dataframe
Head()
Tail()
loc()
multi()
Which of the following can be used to make a Dataframe?
Series
DataFrame
Structured ndarray
All of the above
Type the syntax that returns the top 5 rows in DataFrame df with the native Pandas function (not slicing):
(a)
Find the missing word:
import pandas as pd
students=pd._____________ ([["Khalid", 15]])
pandas
DataFrame
dataframe
Which brackets are correct:
students=pd.DataFrame_ _ _ "Khalid", 15]])
( [ [
((
( [ [ [ [
The instructor wants to add a new column, Marks to the dataframe. The values of the marks will be 12, 22, 21, 24. Help him to choose the correct command to do so.
a) Df.columns=[12, 22, 21, 24]
b) df[‘marks’] = [12, 22, 21, 24]
c) df.loc[marks] = [12, 22, 21, 24]
d) Both (b) and (c) are correct
Which of the following commands is used to convert array named "grades" into data frame named "df_grades"?
df_grades = grades
df_grades = pd.DataFrame(grades)
df_grades = pd.DataFrame("grades")
grades = pd.DataFrame(df_grades)
_________ function is used to access individual values
it ()
bit ()
at ()
set ()
___________ attribute is used to specify column labels
column ()
column
columns()
columns
To get number of elements in a DataFrame _____ attribute may be used.
size
shape
values
ndim
For the given DataFrame df, what will be the code to get the value 38?
df . iloc [1,1]
df . Age [222]
df . iat [1,1]
df . at [222,'Age']
Given the dataframe
d1=pd.DataFrame( {'A':[1,2,3],'B':[4,5,6],'C':[7,8,9] } ) .
Find the output of print(d1.loc['A':'B',:]
0 1 2
A 1 2 3
B 4 5 6
0 1 2
A 1 2 3
0 1 2
B 4 5 6
Given a dataframe df with 2 columns rollno and age .Find out the right code to add a new column class and assign a values NaN
df.class=np.NaN
df['class']=np.NaN
df['class']=[np.NaN]
Given the dataframe df=
Toys Books
EKM 789 234
TVM 567 456
CLT 459 345
Find the result of df.loc['EKM','Toys':'Books']=[700,800]
Toys Books
EKM 789 234
TVM 567 456
CLT 459 345
Toys Books
EKM 789 234
TVM 700 800
CLT 459 345
Toys Books
EKM 700 800
TVM 567 456
CLT 459 345
Toys Books
EKM 789 234
TVM 567 456
CLT 459 345
Which function in Pandas is used for deleting rows?
delete()
del()
cut()
drop()
For selecting rows by an integer location, which function do we use in Pandas?
loc()
iloc()
pop()
append()
Consider the given dataframe df.
Rename the columns 'JAN' ,'FEB' to 'JANUARY' and 'FEBRUARY' and the index 'P1' to 'P100'.
Among the following which one is correct?
df=df.rename(index={'P1':'P100'},columns={'JAN':'JANUARY','FEB':'FEBRUARY'})
df.rename(index={'P1':'P100'},columns={'JAN':'JANUARY','FEB':'FEBRUARY'})
df.rename(index={'P1':'P100'},columns={'JAN':'JANUARY','FEB':'FEBRUARY'},inplace=True)
To iterate over horizontal subsets of DataFrame __________function may be used.
iterate
itercols( )
iterrows( )
iteritems( )
The __________ attribute of a dataframe object returns the row labels of the dataframe.
index
rows
columns
values
To obtain the number of axes or array dimensions of a dataframe object, you can check _____ attribute of the dataframe.
index
size
ndim
shape
To extract row/column from a dataframe, ______ function may be used.
row()
column()
loc()
All of these
DataFramedf
Age Name
rank1 28 Tom
rank2 34 Jack
rank3 29 Steve
rank4 42 Ricky
Find out the command used to get the following output from the above dataframe,
Age
rank1 28
rank2 34
rank3 29
rank4 42
Print(df[‘Age’])
print(df[‘Age’])
print(df(‘Age’))
Print(df[‘Age’], axis=1)
Predict the o/p of the following:
import pandas as pd
x=["ab",'cd','ef','gh']
df=pd.DataFrame(x)
print(df[-2:])
0
2 ef
3 gh
0
1 cd
2 ef
3 gh
0
3 ef
2 gh
Given the dataframe
d1=pd.DataFrame( {'A':[1,2,3],'B':[4,5,6],'C':[7,8,9] } ) .
Find the output of print(d1.loc['A':'B',:]
A 1 2 3
B 4 5 6
0 1 2
A 1 2 3
0 1 2
B 4 5 6
