Pandas Library Fundamentals
- 38Unfamiliar
- 0Learning
- 0Familiar
- 0Mastered
What is pandas and what is it used for?
38 questions
- 1
What is pandas and what is it used for?
Model answer
Pandas is an open-source Python library designed for data manipulation and analysis.
Explanation
Pandas is widely used in data science, AI, and machine learning for handling structured data.
- 2
What are the two core data structures in pandas?
Model answer
Series (a 1D labeled array) and DataFrame (a 2D labeled data structure like a spreadsheet or SQL table).
Explanation
A Series represents a single column or row, while a DataFrame represents a full table of data.
- 3
What is the standard import statement for pandas?
Model answer
import pandas as pdExplanation
It is common practice to alias pandas as
pdfor brevity. - 4
How do you install pandas using pip on Windows?
Model answer
Run
pip install pandasin the terminal or command prompt.Explanation
This command installs pandas from PyPI.
- 5
How do you install pandas on Mac or Linux?
Model answer
Use
pip3 install pandasin the terminal.Explanation
On Unix-based systems,
pipis often for Python 2, sopip3is used for Python 3. - 6
How can you set up a virtual environment for pandas using UV?
Model answer
Use
uv init .to create a virtual environment, thenuv add pandasto install pandas, and run scripts withuv run script.py.Explanation
UV provides a fast way to manage Python virtual environments.
- 7
How do you load a CSV file into a pandas DataFrame?
Model answer
Use
pd.read_csv('filename.csv')which returns a DataFrame.Explanation
This is the most common way to import tabular data into pandas.
- 8
What other file formats can pandas read besides CSV?
Model answer
Pandas can read Excel spreadsheets, and you can also manually create a DataFrame from a dictionary.
Explanation
pd.read_excel('file.xlsx')loads Excel data;pd.DataFrame(dict)creates from a dictionary. - 9
How can you create a DataFrame from a dictionary?
Model answer
Pass a dictionary where keys are column names and values are lists of data to
pd.DataFrame(dict).Explanation
Each key-value pair becomes a column in the DataFrame.
- 10
What are default row indices in a DataFrame?
Model answer
By default, rows are assigned integer indices starting from 0.
Explanation
This index is automatically generated when loading or creating a DataFrame.
- 11
What does the
head()method do?Model answer
It returns the first 5 rows of the DataFrame.
Explanation
Useful for quickly inspecting the beginning of the data.
- 12
What does the
tail()method do?Model answer
It returns the last 5 rows of the DataFrame.
Explanation
Complementary to
head()for checking the end of the data. - 13
What information does
info()provide?Model answer
It provides general information such as the number of entries, columns, and data types of each column.
Explanation
Useful for understanding the structure and memory usage of the DataFrame.
- 14
What does
describe()do?Model answer
It generates descriptive statistics summarizing central tendency, dispersion, and shape of the data.
Explanation
Provides summary statistics for numeric columns by default.
- 15
How do you get a list of column names in a DataFrame?
Model answer
Use
df.columns.Explanation
Returns an Index object containing the column labels.
- 16
What does
df.indexreturn?Model answer
It returns a RangeIndex object with start, stop, and step.
Explanation
The index is a built-in pandas object used for row identification.
- 17
How do you access a single column from a DataFrame?
Model answer
Use
df['column_name']ordf.column_name, which returns a Series.Explanation
Bracket notation and dot notation are equivalent for column access.
- 18
How do you access multiple columns?
Model answer
Use
df[['col1', 'col2']], which returns a DataFrame.Explanation
Pass a list of column names inside the brackets to select multiple columns.
- 19
How do you access a row by its integer position?
Model answer
Use
df.iloc[row_index], which returns a Series.Explanation
ilocstands for integer location, used for positional indexing. - 20
How do you access a row by a label or condition?
Model answer
Use
df.loc[condition]ordf.loc[row_label]for label-based selection.Explanation
locis used for label-based indexing, often with boolean conditions. - 21
How do you filter rows where a column equals a specific value?
Model answer
Use
df[df['col'] == value].Explanation
The condition inside the brackets returns a boolean Series used to filter rows.
- 22
How do you apply multiple filter conditions with AND?
Model answer
Use
&between conditions, each enclosed in parentheses:df[(condition1) & (condition2)].Explanation
The ampersand
&acts as a logical AND operator for element-wise comparison. - 23
How do you apply multiple filter conditions with OR?
Model answer
Use
|between conditions:df[(condition1) | (condition2)].Explanation
The pipe
|acts as a logical OR operator. - 24
How do you filter rows using a string method like 'starts with'?
Model answer
Use
df['col'].str.startswith('pattern').Explanation
The
.straccessor enables vectorized string methods on a Series. - 25
How do you filter rows where a column value is in a list?
Model answer
Use
df['col'].isin(['val1', 'val2']).Explanation
The
isinmethod checks membership of each element in the given list. - 26
How do you invert a filter condition?
Model answer
Use the tilde operator
~before the condition.Explanation
The
~operator negates the boolean condition. - 27
How do you update a value in a specific row and column?
Model answer
Use
df.loc[condition, 'column'] = new_value.Explanation
locselects the rows that meet the condition, then the column is assigned a new value. - 28
How do you apply a transformation to an entire column (e.g., convert to uppercase)?
Model answer
Assign the transformed column:
df['col'] = df['col'].str.upper().Explanation
This replaces the original column with the transformed version.
- 29
How do you drop a row by its index?
Model answer
Use
df.drop(index).Explanation
The
dropmethod removes the specified row index and returns a new DataFrame by default. - 30
How do you drop rows with any missing values?
Model answer
Use
df.dropna().Explanation
This removes any row that contains at least one missing (NaN) value.
- 31
How do you fill missing values with a specific value?
Model answer
Use
df.fillna(value).Explanation
This replaces all NaN values with the specified value.
- 32
What does the
inplace=Trueparameter do?Model answer
It modifies the existing DataFrame instead of returning a new one.
Explanation
When
inplace=True, the operation is performed directly on the original object. - 33
How do you rename a column in a DataFrame?
Model answer
Use
df.rename(columns={'old_name': 'new_name'}, inplace=True).Explanation
The
columnsparameter maps old column names to new ones. - 34
What does
value_counts()do?Model answer
It returns a Series containing counts of unique values in a column.
Explanation
This is useful for frequency analysis of categorical data.
- 35
How do you group data by a column and sum another column?
Model answer
Use
df.groupby('col')['another_col'].sum().Explanation
groupbycreates groups, then an aggregation function likesumis applied to the specified column. - 36
What does
groupby()return before aggregation?Model answer
It returns a GroupBy object, which can then have aggregation methods like
sum(),mean(), etc.Explanation
The GroupBy object is a special object that supports split-apply-combine operations.
- 37
How do you sort a DataFrame by a column?
Model answer
Use
df.sort_values('col', ascending=True/False).Explanation
The
ascendingparameter controls the sort order (True for ascending, False for descending). - 38
How do you save a DataFrame to a CSV file?
Model answer
Use
df.to_csv('filename.csv', index=True/False).Explanation
The
indexparameter determines whether to include the row index in the output file.

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