WorksheetsXII TERM I Dataframes
Total questions: 33
Worksheet time: 3hrs 45mins
Which among the following options can be used to create a DataFrame in Pandas?
A scalar value
An ndarray
A python dict
All of the above
Which function views dataframe in the form of vertical subset ie column wise?
iterrows()
iteritems()
Which of the functions can be used to delete column/row from a DataFrame?
pop()
at()
drop()
iloc()
Which of the following statement/s will give 2 rows from bottom of the dataframe ?
Print(df.tail())
print(df.tail(2))
print(df.tail[2])
print(df.tail(4))
i) Which of the following statement will delete rank2 row from the dataframe ?
df.drop(‘rank2’)
df.drop(rank2)
delete df(rank2)
df.del(“rank2”)
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
The __________ attribute of a dataframe object returns the row labels of a dataframe.
columns
Columns
Index.Values
index.values
Say true or false, A Dataframe object is mutable.
True
False
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)
The instructor wants to know the age of the persons with rank3. Help her to identify the correct set of statement/s from the given options:
a) Print(df.loc[‘rank3’])
b) print(df.iloc[‘rank3’])
c) print(df.loc[‘rank3’])
d) Print(df.loc(‘rank3’))
The acronym csv is short for
Comma Special Values
Comma Separated Values
Case Separated Values
Comma Separate Values
A common format for data interchange
xlsx
csv
docx
table
Method used to bring data from a csv file into a DataFrame
readcsv()
read_table()
read_csv()
read-csv()
Argument used to provide own column headings instead of column headings in csv file
names
header
skiprows
index_col
Select the correct way to give the path of the file in read_csv()
C:/data/myfile.csv
C:\\data\\myfile.csv
C:\data\myfile.csv
C:data/myfile.csv
If the argument header=None is given, what will be the headings
1,2,3 etc
A,B,C etc
0,1,2 etc
I,II,iii
Argument used to skip rows while fetching data from csv file
skiprow
skip_row
SkipRows
skiprows
Default separator of csv
Tab
Space
Comma
Pipe
pd.read_csv(‘data.csv’,skiprows=[1,2,3,6]
What this statement trying to do
Code reads csv file namely data.csv and it will read records 1,2,3,6
Code reads csv file namely data.csv and it will skip 1,2,3,6
Code reads csv file namely data.csv and it will provide headings as 1,2,3,6
Command to be given before doing anything with Pandas
(a)
df['Tid'] & df.Tid are same
true
false
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)
Which of the functions can be used to delete column/row from a DataFrame?
pop()
at()
iloc()
The axis=1 identifies a DataFrame's ____________
Rows
Values
Columns
Data Types
To get number of elements in a DataFrame _____ attribute may be used.
size
shape
values
ndim
To extract a row / column from a DataFrame ___ function may be used
row()
column()
loc()
All of the above
For the given DataFrame df, what will be the code to get the value 38?
df . iloc [1,1]
df . Age [222]
df . loc [111]
None of the above
