Pandas Flashcards
What is a Pandas DataFrame?
A two-dimensional, size-mutable, potentially heterogeneous tabular data structure with labeled axes (rows and columns).
True or False: A Pandas Series is one-dimensional.
True
Fill in the blank: To create a DataFrame from a dictionary, you use the function __________.
pd.DataFrame()
What method is used to read a CSV file into a DataFrame?
pd.read_csv()
How do you access the first 5 rows of a DataFrame?
Using the method df.head()
What is the default index of a new DataFrame?
A RangeIndex starting from 0.
What is the purpose of the .describe() method in Pandas?
It generates descriptive statistics that summarize the central tendency, dispersion, and shape of a DataFrame’s distribution.
True or False: You can have multiple data types in a single DataFrame column.
False
Which function would you use to concatenate two DataFrames?
pd.concat()
What method would you use to drop a column from a DataFrame?
df.drop()
Fill in the blank: The method __________ is used to filter DataFrame rows based on a condition.
df.loc[]
What does the .info() method provide?
It provides a concise summary of a DataFrame, including the index dtype and columns, non-null values, and memory usage.
How can you check for missing values in a DataFrame?
Using the method df.isnull()
What is the purpose of the .groupby() method?
It is used to split the data into groups based on some criteria.
True or False: The index of a DataFrame can be modified after creation.
True
What is the difference between .loc[] and .iloc[]?
.loc[] is label-based indexing, while .iloc[] is position-based indexing.
Which function is used to create a Series from a list?
pd.Series()
Fill in the blank: To sort a DataFrame by a specific column, use the method __________.
df.sort_values()
What does the .apply() method do?
It applies a function along the axis of a DataFrame.
How would you reset the index of a DataFrame?
Using the method df.reset_index()
Which method would you use to merge two DataFrames on a key column?
pd.merge()
True or False: The shape attribute of a DataFrame returns the number of rows and columns.
True
What does the .pivot_table() method do?
It creates a spreadsheet-style pivot table as a DataFrame.
Fill in the blank: The __________ function is used to create a DataFrame from a NumPy array.
pd.DataFrame()
What does the .value_counts() method return?
It returns a Series containing counts of unique values.
Which method is used to fill missing values in a DataFrame?
df.fillna()
What is the primary data structure used in pandas?
DataFrame
True or False: The ‘read_csv’ function is used to read CSV files into a DataFrame.
True
What function is used to display the first few rows of a DataFrame?
head()
Fill in the blank: The function ‘describe()’ provides a summary of the ________ statistics of a DataFrame.
descriptive
Which function is used to filter rows in a DataFrame based on a condition?
loc[]
What does the ‘groupby()’ function do in pandas?
It is used to split the data into groups based on some criteria.
True or False: The ‘drop()’ function can be used to remove rows or columns from a DataFrame.
True
What is the purpose of the ‘merge()’ function in pandas?
To combine two DataFrames based on a common key.
Which method is used to sort a DataFrame by the values of one or more columns?
sort_values()
Fill in the blank: The ‘pivot_table()’ function is used to create a ________ table from a DataFrame.
pivot
What is the function used to check for missing values in a DataFrame?
isnull()
True or False: The ‘apply()’ method allows you to apply a function along an axis of the DataFrame.
True
What function is used to concatenate two or more DataFrames?
concat()
Which pandas function can be used to change the data type of a column?
astype()
What does the ‘value_counts()’ function do?
It returns a Series containing counts of unique values in a column.
Fill in the blank: The ‘fillna()’ function is used to fill ________ values in a DataFrame.
NaN
What method would you use to reset the index of a DataFrame?
reset_index()
True or False: The ‘iloc[]’ function is used for label-based indexing.
False
What function is used to get the number of rows and columns in a DataFrame?
shape
Fill in the blank: The ‘astype()’ function can convert a column to a ________ type.
specific
Which function is used to plot data from a DataFrame?
plot()
What does the ‘to_csv()’ function do?
It writes a DataFrame to a CSV file.
True or False: The ‘sample()’ function is used to return a random sample of items from a DataFrame.
True
What pandas function can be used to create a new column based on existing columns?
assign()
What does the ‘corr()’ function calculate in a DataFrame?
It computes pairwise correlation of columns.
Fill in the blank: The ‘set_index()’ function sets a column as the new ________ of the DataFrame.
index
What is Pandas primarily used for?
Data manipulation and analysis.
True or False: Pandas is built on top of NumPy.
True.
What is the primary data structure used in Pandas?
DataFrame.
Fill in the blank: A __________ is a one-dimensional labeled array capable of holding any data type in Pandas.
Series.
Which function is used to read a CSV file into a DataFrame?
pd.read_csv()
What method would you use to get the first five rows of a DataFrame?
head()
What does the method ‘info()’ do when called on a DataFrame?
It provides a summary of the DataFrame including the data types and non-null counts.
True or False: The ‘iloc’ method is used for label-based indexing.
False.
What method would you use to filter rows based on a condition?
Boolean indexing.
Which function is used to concatenate two DataFrames?
pd.concat()
What is the purpose of the ‘groupby()’ method?
To split the data into groups based on some criteria.
True or False: The ‘apply()’ function can be used to apply a function along an axis of the DataFrame.
True.
What method would you use to drop rows with missing values?
dropna()
What does the ‘pivot_table()’ function do?
Creates a spreadsheet-style pivot table as a DataFrame.
Fill in the blank: The __________ function is used to compute basic statistics like mean, median, and standard deviation.
describe()
What is the purpose of the ‘merge()’ function?
To combine two DataFrames based on a key or index.
True or False: The ‘set_index()’ method allows you to set one or more columns as the index of a DataFrame.
True.
What does the ‘sort_values()’ method do?
Sorts the DataFrame by the values of one or more columns.
Which method would you use to rename columns in a DataFrame?
rename()
Fill in the blank: The __________ method is used to reset the index of a DataFrame.
reset_index()
What is the purpose of the ‘astype()’ method?
To cast a pandas object to a specified dtype.
What does the ‘value_counts()’ method return?
A Series containing counts of unique values.
True or False: You can perform element-wise operations on Series and DataFrames.
True.
What method would you use to save a DataFrame to a CSV file?
to_csv()
What does the ‘duplicated()’ method check for?
It checks for duplicate rows in a DataFrame.
Fill in the blank: To replace values in a DataFrame, you can use the __________ method.
replace()