Page 82 - Informatics_Practices_Fliipbook_Class12
P. 82
8. We can use the following statements to retrieve those columns of DataFrame df whose names
begining with letter 'A': _________
mask = df.columns.str.startswith('A')
data = df.loc[:, mask]
9. In the method read_csv(), we set the input argument index_col=1 to set the first column as
the row label. _________
10. We can explicitly specify the column delimiter using either the delimiter or sep keyword
argument while invoking the read_csv() function. _________
C. Fill in the blanks.
1. We can use the _________ function to create a Pandas DataFrame using a dictionary.
2. To read a CSV file into the DataFrame, we can use _________ function.
3. To retrieve multiple columns from a DataFrame, we can provide a _________ containing the column names inside square
brackets after the DataFrame.
4. The function _________ can be used to retrieve first few (say, n) rows of the DataFrame.
5. The keyword argument _________ of pd.read_csv() can be set to None to indicate that there is no header row
comprising column names in the CSV file to be read.
6. To slice rows and columns in a DataFrame using label-based indexing, we can use the _________ attribute.
7. To set row labels in a DataFrame, we can use the _________ attribute of the DataFrame.
8. The _________ attribute of the DataFrame returns a tuple comprising the number of rows and columns.
9. The _________ attribute is used to retrieve the type of objects in various columns of a DataFrame.
10. The keyword argument _________ of the method pd.read_csv() can be used to specify the list of irrelevant rows.
D. Answer the following questions:
1. What is the difference between loc and iloc attribute of Pandas DataFrame?
Ans. The loc method is used to access elements in a Pandas DataFrame using label-based indexing, while the iloc method is used
to access elements in a Pandas DataFrame using integer positional indexing.
2. Consider the following dictionary-based data:
data = {
'Name': ['Rohan', 'Jasmine', 'Mohit', 'Anshika'],
'Age': [25, 30, 28, 32],
'Gender': ['M', 'F', 'M', 'M'],
'Height': [175, 160, 180, 165],
'Weight': [70, 55, 80, 60]
}
Write a statement to create a Pandas DataFrame df using the above dictionary. Also write a statement to display the
contents of the dataframe.
Ans. df = pd.DataFrame(data)
print(df)
3. Consider the following Pandas DataFrame df:
Name Age Gender Height Weight
0 Rohan 25 M 175 70
1 Jasmine 30 F 160 55
2 Mohit 28 M 180 80
3 Anshika 32 F 165 60
68 Touchpad Informatics Practices-XII

