0% found this document useful (0 votes)
19 views

Python Pandas

Contains Python Pandas MCQs with options and answers

Uploaded by

shreya0473
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views

Python Pandas

Contains Python Pandas MCQs with options and answers

Uploaded by

shreya0473
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 15

Python: Panndas

Pandas is a popular open-source data manipulation and analysis library for Python. It
provides powerful data structures and tools for working with structured data, making it
an essential tool for data scientists, analysts, and developers working with tabular and
time series data. Here's a detailed overview of pandas:

Key Features:

1.
Data Structures:
2.
 Series: 1-dimensional labeled array capable of holding any data type.
 DataFrame: 2-dimensional labeled data structure with columns of potentially
different types, akin to a spreadsheet or SQL table.
 Index: Immutable sequence used for indexing and aligning data.
3.
Data Input/Output:
4.
 Supports reading and writing data from/to various file formats such as CSV,
Excel, SQL databases, JSON, HTML, HDF5, Parquet, and more.
 Efficient handling of large datasets.
5.
Data Manipulation:
6.
 Powerful methods for selecting, filtering, and transforming data.
 Ability to handle missing data easily with methods like dropna(), fillna().
 Grouping and aggregation operations using groupby() function.
 Merging and joining datasets with merge() and join() functions.
7.
Data Cleaning and Preparation:
8.
 Handling duplicate data with drop_duplicates() function.
 Reshaping and pivoting data with pivot() and pivot_table() functions.
 Renaming columns, changing data types, and handling outliers.
9.
Data Analysis:
10.
 Descriptive statistics like mean, median, mode, standard deviation, etc.
 Time series analysis with built-in functionality for date/time indexing and
resampling.
11.
Data Visualization:
12.
 Integration with popular visualization libraries like Matplotlib and Seaborn.
 Quick plotting of data using plot() function directly on pandas objects.
13.
Performance:
14.
 Optimized for performance and scalability, especially for handling large
datasets.
 Efficient memory usage with support for out-of-core computation.

Example Usage:
python
Copy code
import pandas as pd
# Creating a DataFrame
data = {'Name': ['John', 'Anna', 'Peter', 'Linda'],
'Age': [25, 30, 35, 40],
'City': ['New York', 'Paris', 'London', 'Tokyo']}
df = pd.DataFrame(data)
# Reading data from a CSV file
df = pd.read_csv('data.csv')
# Selecting data
df['Age'] # Selecting a single column
df.loc[df['Age'] > 30] # Selecting rows based on a condition
# Data manipulation
df['Age'] += 1 # Incrementing age by 1
df['City'].str.upper() # Converting city names to uppercase
# Data analysis
df.describe() # Summary statistics
df.groupby('City').mean() # Mean age by city
# Data visualization
df['Age'].plot(kind='hist') # Histogram of ages

Installation:

You can install pandas using pip:

Copy code
pip install pandas

Conclusion:

Pandas is an indispensable tool for data manipulation and analysis in Python. Its
intuitive syntax, powerful functionality, and excellent performance make it the go-to
choice for handling structured data in various domains, including finance, research,
machine learning, and more. Whether you're cleaning messy data, performing
complex analyses, or visualizing insights, pandas provides the tools you need to work
efficiently with your data.

MCQs

1. What is pandas?
- A) A snake species
- B) A data manipulation and analysis library in Python
- C) A type of data visualization tool
- D) A web development framework
- **Answer: B**

2. Which of the following data structures is NOT provided by pandas?


- A) Series
- B) Array
- C) DataFrame
- D) Index
- **Answer: B**
3. Which function is used to read a CSV file in pandas?
- A) `read_file()`
- B) `load_csv()`
- C) `read_csv()`
- D) `import_csv()`
- **Answer: C**

4. What is the primary data structure in pandas for holding 1-dimensional data?
- A) Array
- B) DataFrame
- C) Series
- D) List
- **Answer: C**

5. Which of the following is NOT a valid method for handling missing data in pandas?
- A) `dropna()`
- B) `fillna()`
- C) `replace()`
- D) `interpolate()`
- **Answer: C**

6. How can you rename columns in a pandas DataFrame?


- A) Using `rename_column()` method
- B) Accessing columns directly and assigning new names
- C) Using `modify_column_names()` function
- D) Using `rename()` method
- **Answer: D**

7. What function is used for grouping data in pandas?


- A) `group()`
- B) `aggregate()`
- C) `groupby()`
- D) `combine()`
- **Answer: C**

8. Which of the following methods can be used for merging two DataFrames in pandas?
- A) `concat()`
- B) `join()`
- C) `merge()`
- D) All of the above
- **Answer: D**

9. What does the `describe()` method in pandas provide?


- A) Descriptive statistics of the data
- B) Data visualization
- C) Summary of data types
- D) Information about missing values
- **Answer: A**

10. How can you plot data directly from a pandas DataFrame?
- A) Using `matplotlib.pyplot.plot()`
- B) Using `pandas.plot()`
- C) Using `seaborn.plot()`
- D) Using `DataFrame.plot()`
- **Answer: D**

11. How can you drop duplicate rows from a DataFrame?


- A) `remove_duplicates()`
- B) `drop_duplicates()`
- C) `drop_dupes()`
- D) `deduplicate()`
- **Answer: B**

12. Which method is used for performing element-wise arithmetic operations between two
DataFrames in pandas?
- A) `add()`
- B) `merge()`
- C) `combine()`
- D) `apply()`
- **Answer: A**

13. What function is used to convert strings to uppercase in a pandas Series?


- A) `to_upper()`
- B) `str_upper()`
- C) `upper()`
- D) `str.upper()`
- **Answer: D**

14. Which of the following is NOT a valid method to select data in pandas?
- A) Using square brackets `[]`
- B) Using `.loc[]`
- C) Using `.ix[]`
- D) Using `.select()`
- **Answer: D**

15. What does the `dtypes` attribute of a DataFrame in pandas provide?


- A) The number of rows and columns
- B) The data types of each column
- C) The index of the DataFrame
- D) The shape of the DataFrame
- **Answer: B**

16. Which of the following methods is used for forward filling missing values in pandas?
- A) `ffill()`
- B) `fill_forward()`
- C) `forward_fill()`
- D) `forward_fillna()`
- **Answer: A**

17. In pandas, what is used to perform vectorized string operations on a Series?


- A) `.apply()`
- B) `.str()`
- C) `.map()`
- D) `.vectorize()`
- **Answer: B**

18. Which function is used to sort the index of a DataFrame in pandas?


- A) `sort_index()`
- B) `sort_values()`
- C) `order_index()`
- D) `index_sort()`
- **Answer: A**

19. What does the `nunique()` method in pandas return?


- A) Number of unique values in each column
- B) Number of unique values in the DataFrame
- C) Number of non-null values in each column
- D) Number of null values in the DataFrame
- **Answer: A**

20. Which of the following is NOT a valid parameter for the `read_csv()` function in pandas?
- A) `header`
- B) `rows`
- C) `index_col`
- D) `dtype`
- **Answer: B**

21. How can you change the data type of a column in a DataFrame in pandas?
- A) Using the `.astype()` method
- B) Using the `.change_dtype()` method
- C) Using the `.modify_dtype()` method
- D) Using the `.convert_dtype()` method
- **Answer: A**

22. Which of the following methods can be used to pivot data in pandas?
- A) `pivot()`
- B) `transpose()`
- C) `reshape()`
- D) `pivot_table()`
- **Answer: D**

23. What does the `to_csv()` method in pandas do?


- A) Converts a DataFrame to a CSV file
- B) Converts a CSV file to a DataFrame
- C) Converts a DataFrame to an Excel file
- D) Converts an Excel file to a DataFrame
- **Answer: A**

24. Which of the following is NOT a valid aggregation function in pandas?


- A) `mean()`
- B) `median()`
- C) `mode()`
- D) `midpoint()`
- **Answer: D**

25. What does the `drop()` method do in pandas?


- A) Drops rows or columns from a DataFrame
- B) Drops missing values from a DataFrame
- C) Drops duplicates from a DataFrame
- D) Drops specified elements from a DataFrame
- **Answer: A**

26. How can you apply a function to each element in a pandas Series?
- A) Using a for loop
- B) Using the `.apply

()` method
- C) Using the `.map()` method
- D) Using the `.transform()` method
- **Answer: B**
27. What does the `resample()` method in pandas do?
- A) Reshapes the DataFrame
- B) Resamples time series data
- C) Reverses the DataFrame
- D) Replaces missing values
- **Answer: B**

28. Which of the following methods is used to extract specific rows and columns from a DataFrame in
pandas?
- A) `.iloc[]`
- B) `.loc[]`
- C) `.ix[]`
- D) All of the above
- **Answer: D**

29. How can you perform a left join between two DataFrames in pandas?
- A) Using the `left_join()` method
- B) Using the `join()` method with `how='left'` parameter
- C) Using the `merge()` method with `how='left'` parameter
- D) Using the `concat()` method with `join='left'` parameter
- **Answer: C**

30. Which function is used to calculate the correlation between columns in a DataFrame in pandas?
- A) `correlate()`
- B) `covariance()`
- C) `corr()`
- D) `correlation()`
- **Answer: C**

31. How can you check for missing values in a DataFrame in pandas?
- A) Using the `is_missing()` method
- B) Using the `missing_values()` function
- C) Using the `isna()` or `isnull()` methods
- D) Using the `check_missing()` function
- **Answer: C**

32. Which of the following is NOT a valid parameter for the `pivot_table()` function in pandas?
- A) `index`
- B) `columns`
- C) `values`
- D) `groups`
- **Answer: D**

33. What does the `cumsum()` method in pandas do?


- A) Calculates the cumulative sum of elements
- B) Calculates the cumulative product of elements
- C) Calculates the cumulative mean of elements
- D) Calculates the cumulative variance of elements
- **Answer: A**

34. How can you drop a column from a DataFrame in pandas?


- A) Using the `remove_column()` method
- B) Using the `drop_column()` method
- C) Using the `drop()` method with `axis=1` parameter
- D) Using the `delete()` method with `column=True` parameter
- **Answer: C**
35. What does the `explode()` method in pandas do?
- A) Creates explosions in the DataFrame
- B) Expands lists in a column into separate rows
- C) Concatenates multiple DataFrames
- D) Adds new columns to the DataFrame
- **Answer: B**

36. Which of the following is NOT a valid method for reindexing in pandas?
- A) `reindex()`
- B) `reset_index()`
- C) `set_index()`
- D) `index()`
- **Answer: D**

37. How can you create a new column in a DataFrame based on values from existing columns?
- A) Using the `create_column()` method
- B) Using the `add_column()` method
- C) Using assignment with square brackets `[]`
- D) Using the `insert_column()` method
- **Answer: C**

38. What does the `agg()` method in pandas do?


- A) Aggregates data using one or more operations
- B) Aggressively modifies the DataFrame
- C) Agitates the DataFrame
- D) Aggravates data inconsistencies
- **Answer: A**

39. How can you select the first `n` rows of a DataFrame in pandas?
- A) Using the `head(n)` method
- B) Using the `first(n)` method
- C) Using the `select_first(n)` method
- D) Using the `top(n)` method
- **Answer: A**

40. What does the `merge()` method in pandas do?


- A) Merges two DataFrames based on common columns or indices
- B) Merges multiple DataFrames into one
- C) Merges rows and columns in a DataFrame
- D) Merges values within a DataFrame
- **Answer: A**

41. Which function is used to check if a value exists in a pandas Series?


- A) `contains()`
- B) `has_value()`
- C) `exists()`
- D) `isin()`
- **Answer: D**

42. How can you convert a DataFrame to a NumPy array in pandas?


- A) Using the `to_numpy()` method
- B) Using the `as_array()` method
- C) Using the `convert_to_array()` method
- D) Using the `array()` method
- **Answer: A**

43. What does the `shift()` method in pandas do?


- A) Shifts the index of the DataFrame
- B) Shifts the values of the DataFrame
- C) Shifts the columns of the DataFrame
- D) Shifts the rows of the DataFrame
- **Answer: B**

44. How can you drop rows with missing values in a DataFrame in pandas?
- A) Using the `dropna()` method
- B) Using the `remove_missing()` method
- C) Using the `drop_missing()` method
- D) Using the `delete_missing()` method
- **Answer: A**

45. Which method is used to calculate the mean of each group in a DataFrame in pandas?
- A) `group_mean()`
- B) `mean_group()`
- C) `groupby().mean()`
- D) `aggregate_mean()`
- **Answer: C**

46. What does the `stack()` method in pandas do?


- A) Stacks the DataFrame vertically
- B) Stacks the DataFrame horizontally
- C) Stacks the DataFrame along the columns
- D) Stacks the DataFrame along the index
- **Answer: D**

47. How can you perform multi-level indexing in pandas?


- A) Using the `set_index()` method with multiple columns
- B) Using the `multi_index()` method
- C) Using the `index_multi()` method
- D) Using the `stack()` method with multiple levels
- **Answer: A**

48. What does the `pivot()` method in pandas do?


- A) Pivots rows and columns in a DataFrame
- B) Pivots a Series into a DataFrame
- C) Pivots a DataFrame into a Series
- D) Pivots values within a DataFrame
- **Answer: A**

49

. Which of the following methods can be used to fill missing values in a DataFrame in pandas?
- A) `fill()`
- B) `fill_missing()`
- C) `fill_value()`
- D) `fillna()`
- **Answer: D**

50. How can you reset the index of a DataFrame in pandas?


- A) Using the `reset_index()` method
- B) Using the `reindex()` method
- C) Using the `index_reset()` method
- D) Using the `reset()` method
- **Answer: A**
51. What does the `at_time()` method in pandas do?
- A) Returns data at a specific time
- B) Returns data after a specific time
- C) Returns data before a specific time
- D) Returns data within a specific time range
- **Answer: A**

52. How can you select rows based on a condition in pandas?


- A) Using the `select()` method
- B) Using the `filter()` method
- C) Using conditional indexing with square brackets `[]`
- D) Using the `where()` method
- **Answer: C**

53. What does the `melt()` method in pandas do?


- A) Melts the DataFrame into a Series
- B) Melts the DataFrame into a long format
- C) Melts the DataFrame into a wide format
- D) Melts the DataFrame into a tidy format
- **Answer: B**

54. Which method is used to calculate the cumulative maximum of elements in a DataFrame in
pandas?
- A) `cummax()`
- B) `max_cum()`
- C) `cumulative_max()`
- D) `maximum_cum()`
- **Answer: A**

55. What does the `shift()` method do with negative values in pandas?
- A) Shifts the values to the left
- B) Shifts the values to the right
- C) Shifts the index to the left
- D) Shifts the index to the right
- **Answer: B**

56. How can you rename the index of a DataFrame in pandas?


- A) Using the `rename_index()` method
- B) Using the `set_index()` method with the `rename` parameter
- C) Using the `index_rename()` method
- D) Using the `rename()` method with the `index` parameter
- **Answer: D**

57. What does the `explode()` method do with non-list elements in pandas?
- A) Converts them to lists and expands them into separate rows
- B) Removes them from the DataFrame
- C) Raises an error
- D) Converts them to missing values
- **Answer: C**

58. How can you calculate the median of each column in a DataFrame in pandas?
- A) Using the `median()` method
- B) Using the `agg()` method with the `'median'` parameter
- C) Using the `groupby()` method followed by the `median()` method
- D) Using the `stats()` method with the `'median'` parameter
- **Answer: B**
59. Which method is used to calculate the minimum of each group in a DataFrame in pandas?
- A) `group_min()`
- B) `min_group()`
- C) `groupby().min()`
- D) `aggregate_min()`
- **Answer: C**

60. What does the `to_excel()` method in pandas do?


- A) Converts a DataFrame to an Excel file
- B) Converts an Excel file to a DataFrame
- C) Converts a DataFrame to a CSV file
- D) Converts a CSV file to a DataFrame
- **Answer: A**

61. How can you calculate the skewness of each column in a DataFrame in pandas?
- A) Using the `skewness()` method
- B) Using the `stats()` method with the `'skew'` parameter
- C) Using the `groupby()` method followed by the `skew()` method
- D) Using the `aggregate()` method with the `'skew'` parameter
- **Answer: C**

62. What does the `min_periods` parameter in pandas `rolling()` function specify?
- A) The minimum number of elements required for the rolling window
- B) The minimum value of the rolling window
- C) The minimum period for the rolling window
- D) The minimum index value for the rolling window
- **Answer: A**

63. How can you convert a pandas DataFrame to a JSON object?


- A) Using the `to_json()` method
- B) Using the `convert_to_json()` method
- C) Using the `jsonify()` method
- D) Using the `json.dumps()` function
- **Answer: A**

64. What does the `count()` method in pandas return?


- A) The count of non-null values in each column
- B) The count of null values in each column
- C) The count of unique values in each column
- D) The count of rows in the DataFrame
- **Answer: A**

65. How can you calculate the kurtosis of each column in a DataFrame in pandas?
- A) Using the `kurtosis()` method
- B) Using the `stats()` method with the `'kurt'` parameter
- C) Using the `groupby()` method followed by the `kurt()` method
- D) Using the `aggregate()` method with the `'kurt'` parameter
- **Answer: C**

66. What does the `last()` method in pandas do?


- A) Returns the last row of the DataFrame
- B) Returns the last column of the DataFrame
- C) Returns the last non-null value of each column
- D) Returns the last `n` rows of the DataFrame
- **Answer: D**

67. How can you calculate the percentile of each column in a DataFrame in pandas?
- A) Using the `percentile()` method
- B) Using the `stats()` method with the `'percentile'` parameter
- C) Using the `groupby()` method followed by the `percentile()` method
- D) Using the `aggregate()` method with the `'percentile'` parameter
- **Answer: D**

68. What does the `nlargest()` method in pandas do?


- A) Returns the largest values in each column
- B) Returns the largest values in the DataFrame
- C) Returns the smallest values in each column
- D) Returns the smallest values in the DataFrame
- **Answer: B**

69. How can you calculate the percentage change of each column in a DataFrame in pandas?
- A) Using the `change()` method
- B) Using the `percentage_change()` method
- C) Using the `pct_change

()` method
- D) Using the `change_percentage()` method
- **Answer: C**

70. What does the `ngroup()` method in pandas return?


- A) The number of groups in the DataFrame
- B) The group index of each row
- C) The number of rows in each group
- D) The group index of each column
- **Answer: B**

71. How can you calculate the rank of each column in a DataFrame in pandas?
- A) Using the `rank()` method
- B) Using the `stats()` method with the `'rank'` parameter
- C) Using the `groupby()` method followed by the `rank()` method
- D) Using the `aggregate()` method with the `'rank'` parameter
- **Answer: A**

72. What does the `pipe()` method in pandas do?


- A) Applies a function to each element of the DataFrame
- B) Pipes data from one DataFrame to another
- C) Pipes data from one method to another
- D) Pipes data from one process to another
- **Answer: B**

73. How can you calculate the rolling mean of each column in a DataFrame in pandas?
- A) Using the `rolling_mean()` method
- B) Using the `mean()` method with the `rolling=True` parameter
- C) Using the `groupby()` method followed by the `rolling_mean()` method
- D) Using the `agg()` method with the `'rolling_mean'` parameter
- **Answer: A**

74. What does the `astype()` method in pandas do?


- A) Converts the DataFrame to a specified data type
- B) Converts the columns of the DataFrame to a specified data type
- C) Converts the rows of the DataFrame to a specified data type
- D) Converts the index of the DataFrame to a specified data type
- **Answer: B**
75. How can you calculate the standard deviation of each column in a DataFrame in pandas?
- A) Using the `std()` method
- B) Using the `stats()` method with the `'std'` parameter
- C) Using the `groupby()` method followed by the `std()` method
- D) Using the `aggregate()` method with the `'std'` parameter
- **Answer: A**

76. What does the `truncate()` method in pandas do?


- A) Truncates the DataFrame to a specified length
- B) Truncates the DataFrame to a specified index
- C) Truncates the DataFrame to a specified date range
- D) Truncates the DataFrame to a specified frequency
- **Answer: C**

77. How can you calculate the sum of each column in a DataFrame in pandas?
- A) Using the `sum()` method
- B) Using the `stats()` method with the `'sum'` parameter
- C) Using the `groupby()` method followed by the `sum()` method
- D) Using the `aggregate()` method with the `'sum'` parameter
- **Answer: A**

78. What does the `to_sql()` method in pandas do?


- A) Converts a DataFrame to a SQL database
- B) Converts a SQL database to a DataFrame
- C) Converts a DataFrame to a SQL query
- D) Converts a SQL query to a DataFrame
- **Answer: A**

79. How can you calculate the variance of each column in a DataFrame in pandas?
- A) Using the `variance()` method
- B) Using the `stats()` method with the `'var'` parameter
- C) Using the `groupby()` method followed by the `var()` method
- D) Using the `aggregate()` method with the `'var'` parameter
- **Answer: C**

80. What does the `update()` method in pandas do?


- A) Updates the values of a DataFrame with non-null values from another DataFrame
- B) Updates the index of a DataFrame
- C) Updates the columns of a DataFrame
- D) Updates the data types of a DataFrame
- **Answer: A**

81. How can you calculate the covariance between columns in a DataFrame in pandas?
- A) Using the `covariance()` method
- B) Using the `stats()` method with the `'cov'` parameter
- C) Using the `groupby()` method followed by the `cov()` method
- D) Using the `aggregate()` method with the `'cov'` parameter
- **Answer: A**

82. What does the `lookup()` method in pandas do?


- A) Looks up values in a DataFrame based on row and column indices
- B) Looks up values in a Series based on index values
- C) Looks up values in a DataFrame based on column names
- D) Looks up values in a Series based on column values
- **Answer: A**

83. How can you calculate the cumulative product of each column in a DataFrame in pandas?
- A) Using the `cumprod()` method
- B) Using the `stats()` method with the `'cumprod'` parameter
- C) Using the `groupby()` method followed by the `cumprod()` method
- D) Using the `aggregate()` method with the `'cumprod'` parameter
- **Answer: A**

84. What does the `clip()` method in pandas do?


- A) Clips the DataFrame to a specified length
- B) Clips the DataFrame to a specified range
- C) Clips the DataFrame to a specified index
- D) Clips the DataFrame to a specified frequency
- **Answer: B**

85. How can you calculate the skewness of each column in a DataFrame in pandas?
- A) Using the `skew()` method
- B) Using the `stats()` method with the `'skew'` parameter
- C) Using the `groupby()` method followed by the `skew()` method
- D) Using the `aggregate()` method with the `'skew'` parameter
- **Answer: A**

86. What does the `ffill()` method in pandas do?


- A) Fills missing values with the last non-null value
- B) Fills missing values with the next non-null value
- C) Fills missing values with a specified value
- D) Fills missing values with zero
- **Answer: A**

87. How can you calculate the rolling median of each column in a DataFrame in pandas?
- A) Using the `rolling_median()` method
- B) Using the `median()` method with the `rolling=True` parameter
- C) Using the `groupby()` method followed by the `rolling_median()` method
- D) Using the `agg()` method with the `'rolling_median'` parameter
- **Answer: A**

88. What does the `abs()` method in pandas do?


- A) Returns the absolute values of elements

- B) Returns the sum of absolute values


- C) Returns the maximum absolute value
- D) Returns the minimum absolute value
- **Answer: A**

89. How can you calculate the cumulative sum of each column in a DataFrame in pandas?
- A) Using the `cumsum()` method
- B) Using the `stats()` method with the `'cumsum'` parameter
- C) Using the `groupby()` method followed by the `cumsum()` method
- D) Using the `aggregate()` method with the `'cumsum'` parameter
- **Answer: A**

90. What does the `floordiv()` method in pandas do?


- A) Performs floor division
- B) Performs ceiling division
- C) Performs integer division
- D) Performs modulo division
- **Answer: A**
91. How can you calculate the cumulative maximum of each column in a DataFrame in pandas?
- A) Using the `cummax()` method
- B) Using the `stats()` method with the `'cummax'` parameter
- C) Using the `groupby()` method followed by the `cummax()` method
- D) Using the `aggregate()` method with the `'cummax'` parameter
- **Answer: A**

92. What does the `nlargest()` method in pandas do?


- A) Returns the largest values in each column
- B) Returns the largest values in the DataFrame
- C) Returns the smallest values in each column
- D) Returns the smallest values in the DataFrame
- **Answer: B**

93. How can you calculate the correlation between columns in a DataFrame in pandas?
- A) Using the `correlation()` method
- B) Using the `stats()` method with the `'corr'` parameter
- C) Using the `groupby()` method followed by the `corr()` method
- D) Using the `aggregate()` method with the `'corr'` parameter
- **Answer: C**

94. What does the `last_valid_index()` method in pandas return?


- A) The index of the last valid value
- B) The index of the last non-null value
- C) The index of the last non-missing value
- D) The index of the last value
- **Answer: B**

95. How can you calculate the percentage change of each column in a DataFrame in pandas?
- A) Using the `change()` method
- B) Using the `percentage_change()` method
- C) Using the `pct_change()` method
- D) Using the `change_percentage()` method
- **Answer: C**

96. What does the `rank()` method in pandas do?


- A) Ranks the values in each column
- B) Ranks the values in the DataFrame
- C) Ranks the columns in the DataFrame
- D) Ranks the rows in the DataFrame
- **Answer: A**

97. How can you calculate the rolling standard deviation of each column in a DataFrame in pandas?
- A) Using the `rolling_std()` method
- B) Using the `std()` method with the `rolling=True` parameter
- C) Using the `groupby()` method followed by the `rolling_std()` method
- D) Using the `agg()` method with the `'rolling_std'` parameter
- **Answer: A**

98. What does the `first()` method in pandas do?


- A) Returns the first row of the DataFrame
- B) Returns the first column of the DataFrame
- C) Returns the first non-null value of each column
- D) Returns the first `n` rows of the DataFrame
- **Answer: D**

99. How can you calculate the sum of each row in a DataFrame in pandas?
- A) Using the `sum()` method with the `axis=0` parameter
- B) Using the `sum()` method with the `axis=1` parameter
- C) Using the `groupby()` method followed by the `sum()` method
- D) Using the `aggregate()` method with the `'sum'` parameter
- **Answer: B**

100. What does the `ne()` method in pandas do?


- A) Checks if two DataFrames are not equal
- B) Checks if two columns are not equal
- C) Checks if two values are not equal
- D) Checks if two indices are not equal
- **Answer: C**

You might also like