Pandas Library Fundamentals
- 18Unfamiliar
- 0Learning
- 0Familiar
- 0Mastered
What is the purpose of the pip install pandas command?
What is the purpose of the pip install pandas command?
18 questions
- 1
What is the purpose of the
pip install pandascommand?- A
To install the pandas library into the Python environment
- B
To uninstall pandas from the system
- C
To upgrade pandas to the latest version
- D
To create a virtual environment for pandas
Correct answer
ATo install the pandas library into the Python environment
Explanation
The command
pip install pandasis used to download and install the pandas library into the current Python environment. - A
- 2
What is the standard alias used when importing pandas?
- A
import pandas as panda
- B
import pandas as pan
- C
import pandas as ps
- D
import pandas as pd
Correct answer
Dimport pandas as pd
Explanation
The common practice is to import pandas as
pd, which is shorter and conventional. - A
- 3
What are the two core data structures in pandas?
- A
Array and Matrix
- B
Tuple and Set
- C
List and Dictionary
- D
Series and DataFrame
Correct answer
DSeries and DataFrame
Explanation
Pandas has two main data structures: Series (1D labeled array) and DataFrame (2D labeled data structure).
- A
- 4
Which method is used to read a CSV file into a pandas DataFrame?
- A
pd.import_csv()
- B
pd.csv_to_df()
- C
pd.read_csv()
- D
pd.load_csv()
Correct answer
Cpd.read_csv()
Explanation
The function
pd.read_csv()is used to read a CSV file and return a DataFrame. - A
- 5
What does the
head()method return by default?- A
The first five rows of the DataFrame
- B
All rows with missing values
- C
The last five rows of the DataFrame
- D
The column names and data types
Correct answer
AThe first five rows of the DataFrame
Explanation
df.head()returns the first five rows of the DataFrame by default, useful for a quick preview. - A
- 6
Which method provides descriptive statistics of a DataFrame?
- A
df.describe()
- B
df.summary()
- C
df.stats()
- D
df.analyze()
Correct answer
Adf.describe()
Explanation
df.describe()generates descriptive statistics including count, mean, std, min, quartiles, and max. - A
- 7
How can you access a single column as a Series from a DataFrame
df?- A
df.iloc['column_name']
- B
df.loc['column_name']
- C
df['column_name']
- D
df[['column_name']]
Correct answer
Cdf['column_name']
Explanation
Using
df['column_name']returns a Series containing the column's values. Double brackets return a DataFrame. - A
- 8
What does
df.iloc[0]return?- A
The first row as a Series
- B
The entire DataFrame
- C
The first column as a Series
- D
The first row as a DataFrame
Correct answer
AThe first row as a Series
Explanation
ilocuses integer-based indexing;df.iloc[0]returns the first row as a Series. - A
- 9
To update a specific cell based on a condition, which method is commonly used?
- A
df.set_value(condition, 'column', value)
- B
df.iloc[condition, 'column'] = value
- C
df.update()
- D
df.loc[condition, 'column'] = value
Correct answer
Ddf.loc[condition, 'column'] = value
Explanation
df.loc[condition, 'column'] = valueallows updating values where the condition is true. - A
- 10
Which operator is used to combine multiple conditions in a pandas filter, where all conditions must be true?
- A
& (ampersand)
- B
or
- C
and
- D
| (pipe)
Correct answer
A& (ampersand)
Explanation
In pandas, the
&operator is used for element-wise AND when combining boolean arrays. - A
- 11
How can you filter rows where a string column starts with a specific letter?
- A
df[df['col'].str.starts('letter')]
- B
df[df['col'].startswith('letter')]
- C
df[df['col'].str.like('letter%')]
- D
df[df['col'].str.startswith('letter')]
Correct answer
Ddf[df['col'].str.startswith('letter')]
Explanation
The
.str.startswith()method is used on a string Series to check if each element starts with a given string. - A
- 12
What does the
~operator do when used before a condition in pandas?- A
It checks for missing values
- B
It inverts the boolean condition
- C
It returns the number of rows that match the condition
- D
It casts the condition to a different data type
Correct answer
BIt inverts the boolean condition
Explanation
The tilde
~is used to invert boolean conditions, selecting rows that do NOT satisfy the condition. - A
- 13
Which method removes rows with any null values?
- A
df.clean()
- B
df.remove_null()
- C
df.dropna()
- D
df.fillna()
Correct answer
Cdf.dropna()
Explanation
df.dropna()drops rows (or columns) that contain missing values. - A
- 14
What does
inplace=Truedo in pandas methods?- A
It returns a new DataFrame with the changes applied
- B
It modifies the original DataFrame directly
- C
It creates a copy of the DataFrame
- D
It raises an error if the operation fails
Correct answer
BIt modifies the original DataFrame directly
Explanation
When
inplace=True, the operation is performed directly on the original object without returning a new one. - A
- 15
Which method counts the frequency of each unique value in a Series?
- A
df.value_counts()
- B
df.frequency()
- C
df.count_unique()
- D
df.unique().count()
Correct answer
Adf.value_counts()
Explanation
.value_counts()returns a Series containing counts of unique values. - A
- 16
To group data by a column and compute the sum of another column, which sequence is used?
- A
df.groupby('col1')['col2'].sum()
- B
df.groupby('col1').sum('col2')
- C
df.groupby('col1', 'col2').sum()
- D
df.groupby('col1')['col2'].aggregate(sum)
Correct answer
Adf.groupby('col1')['col2'].sum()
Explanation
Common syntax:
df.groupby('col1')['col2'].sum()groups by 'col1' and sums 'col2' for each group. - A
- 17
How can you sort a DataFrame by a column in descending order?
- A
df.order_by('col', descending=True)
- B
df.sort_values(by='col', descending=True)
- C
df.sort_values(by='col', ascending=False)
- D
df.sort('col', reverse=True)
Correct answer
Cdf.sort_values(by='col', ascending=False)
Explanation
df.sort_values(by='column', ascending=False)sorts the DataFrame in descending order. - A
- 18
Which method saves a DataFrame to a CSV file without including the index column?
- A
df.write_csv('file.csv', index=False)
- B
df.export_csv('file.csv', no_index=True)
- C
df.save('file.csv', index=False)
- D
df.to_csv('file.csv', index=False)
Correct answer
Ddf.to_csv('file.csv', index=False)
Explanation
df.to_csv('file.csv', index=False)writes the DataFrame to a CSV file without the row index. - A

Ask anything
We've read this whole study set, so questions about it get the best answers.