examples Flashcards
“What does the .duplicated()
method do in Pandas?”
“It checks for duplicate rows in a DataFrame and returns a boolean series.”
“How do you remove duplicate rows using Pandas?”
“Use .drop_duplicates()
to remove duplicate rows from a DataFrame.”
“How can you rename columns in a DataFrame?”
“You can rename columns by using the .rename()
method, passing a dictionary with old column names as keys and new names as values.”
“How do you change a column’s data type in Pandas?”
“Use the .astype()
method to change the data type of a column in a DataFrame.”
“What does the .str.contains()
method do in Pandas?”
“The .str.contains()
method is used to check if a string or substring is present in each element of a column.”
“How can you replace substrings in a column using Pandas?”
“You can use the .str.replace()
method to replace substrings in a column.”
“What is the difference between .apply()
, .map()
, and .applymap()
?”
”.apply()
is used on Series or DataFrames for row/column-wise operations. .map()
is used for element-wise operations in a Series. .applymap()
is used for element-wise operations in a DataFrame.”
“What is the purpose of the groupby()
method in Pandas?”
“The groupby()
method is used to group data based on one or more columns and perform operations like aggregation on each group.”
“What are common aggregation functions used in Pandas?”
“Common aggregation functions include sum()
, mean()
, count()
, min()
, and max()
.”
“How do you create a pivot table in Pandas?”
“Use the .pivot_table()
method to create a pivot table from a DataFrame by specifying the rows, columns, and values to aggregate.”
“What does the pd.crosstab()
function do in Pandas?”
“pd.crosstab()
is used to compute a cross-tabulation of two or more factors, essentially creating a contingency table.”
“How do you concatenate DataFrames in Pandas?”
“You can concatenate DataFrames by using pd.concat()
and specifying the axis along which to concatenate.”
“How do you merge two DataFrames on a specific column?”
“Use pd.merge()
to merge DataFrames on a specific column, similar to SQL joins.”
“What is the difference between .join()
and merge()
?”
”.join()
is a method of the DataFrame that is used for joining by index, while merge()
is used for merging by columns.”
“How do you convert a string column to a datetime object in Pandas?”
“Use pd.to_datetime()
to convert a string column to a datetime object.”
“How do you extract the year from a datetime column?”
“Use .dt.year
to extract the year from a datetime column.”
“How do you extract the month and day from a datetime column?”
“Use .dt.month
to extract the month and .dt.day
to extract the day.”
“What does .resample()
do in Pandas?”
“The .resample()
method is used for resampling time series data, allowing you to aggregate or downsample at different time frequencies.”
“What is the purpose of rolling window operations like rolling().mean()
?”
“Rolling window operations like rolling().mean()
allow you to calculate a moving average or apply other functions over a sliding window of data.”
“How do you set an index for a DataFrame?”
“Use the .set_index()
method to set a column as the index of the DataFrame.”
“How can you reset the index of a DataFrame?”
“Use the .reset_index()
method to reset the index and move the index back to a column.”
“What is the difference between rolling()
and expanding()
?”
“rolling()
computes a moving window function while expanding()
computes cumulative statistics.”
“How do you use the .query()
method in Pandas?”
“The .query()
method allows you to filter data in a DataFrame using a query string.”