Pandas Quiz: Test Your Knowledge#
Part 1: Data Creation#
What function would you use to create a one-dimensional labeled array in Pandas?
a)
pd.DataFrame()b)
pd.Series()c)
pd.read_csv()d)
pd.to_excel()
Which function creates a two-dimensional labeled table in Pandas?
a)
pd.DataFrame()b)
pd.Series()c)
pd.pivot()d)
pd.melt()
Part 2: Data Input/Output (I/O)#
Which function reads a CSV file into a DataFrame?
a)
pd.read_csv()b)
pd.read_sql()c)
pd.read_excel()d)
pd.to_csv()
If you need to export a DataFrame to an Excel file, which function should you use?
a)
pd.read_excel()b)
pd.to_csv()c)
pd.to_excel()d)
pd.read_csv()
Part 3: Data Inspection#
Which function provides a summary of a DataFrame, including data types and non-null counts?
a)
df.head()b)
df.describe()c)
df.info()d)
df.shape
How would you return the dimensions (number of rows and columns) of a DataFrame?
a)
df.describe()b)
df.shapec)
df.dtypesd)
df.head()
Part 4: Data Selection#
What function allows you to select rows or columns based on index positions?
a)
df.loc[]b)
df.iloc[]c)
df['column_name']d)
df.groupby()
How would you access multiple columns (e.g., ‘col1’ and ‘col2’) in a DataFrame?
a)
df[['col1', 'col2']]b)
df['col1']c)
df.loc[]d)
df.iloc[]
Part 5: Data Cleaning#
Which function detects missing values in a DataFrame?
a)
df.dropna()b)
df.notnull()c)
df.isnull()d)
df.fillna()
What function replaces missing values with a specified value?
a)
df.dropna()b)
df.fillna(value)c)
df.rename()d)
df.replace()
Part 6: Data Transformation#
To sort rows of a DataFrame based on a specific column, which function would you use?
a)
df.groupby()b)
df.sort_index()c)
df.sort_values(by='column')d)
df.apply()
Which function groups data for aggregation or transformation?
a)
df.pivot_table()b)
df.groupby()c)
df.astype()d)
df.corr()
Part 7: Data Aggregation#
Which function computes the mean of numeric columns in a DataFrame?
a)
df.sum()b)
df.mean()c)
df.mode()d)
df.median()
How would you calculate the cumulative sum of numeric values in a DataFrame?
a)
df.cumsum()b)
df.sum()c)
df.mean()d)
df.count()
Part 8: Merging and Reshaping#
If you need to combine two DataFrames based on a common column, which function should you use?
a)
pd.concat()b)
pd.merge()c)
df.join()d)
df.melt()
What function converts a DataFrame from wide format to long format?
a)
pd.pivot()b)
df.melt()c)
df.pivot_table()d)
pd.concat()
Part 9: Statistical Operations#
Which function calculates the correlation between numeric columns?
a)
df.cov()b)
df.var()c)
df.corr()d)
df.std()
How would you compute the variance of numeric columns?
a)
df.corr()b)
df.var()c)
df.cumsum()d)
df.median()
Part 10: Time Series Functions#
What function converts data into a datetime object in Pandas?
a)
pd.to_datetime()b)
df.resample()c)
df.shift()d)
df.groupby()
Which function aggregates time series data in Pandas?
a)
df.shift()b)
pd.to_datetime()c)
df.resample()d)
df.groupby()
Answer Key (for self-assessment):
b | 2. a | 3. a | 4. c | 5. c | 6. b | 7. b | 8. a | 9. c | 10. b | 11. c | 12. b | 13. b | 14. a | 15. b | 16. b | 17. c | 18. b | 19. a | 20. c