0% found this document useful (0 votes)
16 views25 pages

Questions

The document consists of a comprehensive set of theoretical and practical questions related to NumPy and pandas, covering topics such as array creation, manipulation, mathematical operations, data handling, and performance optimization. It includes both basic and advanced concepts, along with practical tasks to reinforce learning. The questions are designed to test and enhance understanding of these powerful Python libraries for numerical and data analysis.

Uploaded by

Rupal Gayakwad
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views25 pages

Questions

The document consists of a comprehensive set of theoretical and practical questions related to NumPy and pandas, covering topics such as array creation, manipulation, mathematical operations, data handling, and performance optimization. It includes both basic and advanced concepts, along with practical tasks to reinforce learning. The questions are designed to test and enhance understanding of these powerful Python libraries for numerical and data analysis.

Uploaded by

Rupal Gayakwad
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 25

Theoretical Questions-

Basics of NumPy

1. What is NumPy, and why is it used in Python?


2. What are the key features of NumPy?
3. How is NumPy different from Python lists?
4. Explain the concept of NumPy arrays.
5. What are the advantages of using NumPy arrays over lists?
6. How can you install NumPy in Python?
7. What is the main object in NumPy?
8. What is the difference between numpy.array() and numpy.asarray()?
9. Explain the difference between 1D, 2D, and 3D arrays in NumPy.
10. What is the shape of a NumPy array?

Array Creation

11. How do you create a NumPy array from a list?


12. What are some methods to create arrays in NumPy?
13. How can you create a NumPy array of zeros?
14. How can you create a NumPy array of ones?
15. Explain the use of numpy.linspace() and numpy.arange().
16. How can you create an identity matrix in NumPy?
17. What is the use of numpy.empty()?
18. How can you create an array with random values in NumPy?
19. What is the difference between numpy.random.rand() and numpy.random.randn()?
20. How can you create a diagonal matrix in NumPy?

Array Properties

21. How do you check the dimensions of a NumPy array?


22. How do you find the size of a NumPy array?
23. What is the dtype attribute in NumPy arrays?
24. How do you change the data type of a NumPy array?
25. What is the difference between size and shape attributes in NumPy?
26. How do you determine the memory usage of a NumPy array?
27. Explain the concept of strides in NumPy arrays.
28. What is the ndim attribute in NumPy arrays?
29. How do you flatten a NumPy array?
30. What is the use of numpy.ravel()?

Indexing and Slicing

31. How do you access elements in a NumPy array?


32. Explain slicing in NumPy arrays.
33. How do you access rows and columns in a 2D array?
34. What is boolean indexing in NumPy?
35. How can you use conditional statements for indexing in NumPy?
36. How do you reverse an array in NumPy?
37. What is the use of the numpy.where() function?
38. How do you use fancy indexing in NumPy?
39. Explain the concept of broadcasting in NumPy.
40. How do you extract a subarray from a NumPy array?

Array Manipulation

41. How do you reshape a NumPy array?


42. What is the difference between resize() and reshape()?
43. How do you concatenate arrays in NumPy?
44. What is the use of numpy.vstack() and numpy.hstack()?
45. How can you split a NumPy array?
46. What is the difference between numpy.split() and numpy.array_split()?
47. How do you transpose a NumPy array?
48. What is the use of numpy.swapaxes()?
49. How can you append elements to a NumPy array?
50. What is the difference between numpy.tile() and numpy.repeat()?

Mathematical Operations

51. How do you perform element-wise addition in NumPy?


52. How do you perform matrix multiplication in NumPy?
53. What is the use of numpy.dot()?
54. How can you calculate the sum of elements in a NumPy array?
55. How do you compute the mean, median, and standard deviation in NumPy?
56. What is the use of numpy.sqrt()?
57. How do you find the maximum and minimum values in a NumPy array?
58. What is the use of numpy.cumsum() and numpy.cumprod()?
59. How do you perform element-wise division in NumPy?
60. How do you calculate the determinant of a matrix in NumPy?

Advanced Functions

61. What is the use of numpy.linalg module?


62. How do you solve a system of linear equations using NumPy?
63. What is the use of numpy.eig()?
64. Explain the use of numpy.fft module.
65. How can you compute the inverse of a matrix in NumPy?
66. What is the use of numpy.polyfit()?
67. How do you compute the cross-product of two vectors in NumPy?
68. What is the use of numpy.histogram()?
69. How can you compute the rank of a matrix in NumPy?
70. What is the use of numpy.gradient()?

Random Numbers

71. How do you generate random numbers in NumPy?


72. What is the difference between numpy.random.seed() and
numpy.random.shuffle()?
73. How can you create a random integer array in NumPy?
74. Explain the use of numpy.random.choice().
75. How do you generate random samples from a normal distribution in NumPy?
76. What is the use of numpy.random.permutation()?
77. How can you set a random seed in NumPy?
78. What is the use of numpy.random.uniform()?
79. How do you create a random boolean array in NumPy?
80. Explain the concept of reproducibility in NumPy random number generation.

Data Handling

81. How do you load data from a file into a NumPy array?
82. What is the use of numpy.genfromtxt()?
83. How can you save a NumPy array to a file?
84. What is the difference between numpy.save() and numpy.savetxt()?
85. How do you read a CSV file using NumPy?
86. What is the use of numpy.loadtxt()?
87. How do you handle missing data in NumPy arrays?
88. Explain the use of masks in NumPy.
89. How do you merge two datasets using NumPy?
90. How can you sort a NumPy array?

Performance and Optimization

91. Why is NumPy faster than traditional Python lists?


92. What is vectorization in NumPy?
93. How do you optimize performance in NumPy operations?
94. What is the use of numpy.ufuncs?
95. How can you measure the execution time of a NumPy operation?
96. Explain the use of numpy.vectorize() function.
97. What is the difference between numpy.add() and + operator?
98. How do you handle large datasets in NumPy?
99. What are some common pitfalls when using NumPy?
100. How does NumPy handle type casting during operations?

Practical Questions-

Basics of NumPy

1. Create a 1D NumPy array from a Python list.


2. Create a 2D NumPy array with dimensions 3x3.
3. Convert a Python tuple into a NumPy array.
4. Check the type and shape of a given NumPy array.
5. Change the data type of a NumPy array to float.
6. Create a NumPy array of size 10 filled with zeros.
7. Create a NumPy array of size 10 filled with ones.
8. Create a NumPy array of 10 random integers between 1 and 100.
9. Generate an array of 15 evenly spaced values between 0 and 5.
10. Create an array of 20 random values sampled from a normal distribution.

Indexing and Slicing

11. Extract the first row of a 2D array.


12. Extract the last column of a 2D array.
13. Reverse the elements of a 1D array.
14. Replace all even numbers in an array with -1.
15. Extract all elements greater than 10 from an array.
16. Set the first three elements of an array to zero.
17. Use boolean indexing to filter out negative values from an array.
18. Extract a subarray from a 3x3 array.
19. Replace all values in an array that are divisible by 3 with their square.
20. Use numpy.where() to replace all negative values with zero.

Array Manipulation

21. Reshape a 1D array of size 12 into a 3x4 array.


22. Flatten a 2D array into a 1D array.
23. Concatenate two 1D arrays horizontally.
24. Stack two 2D arrays vertically.
25. Split a 1D array into three equal parts.
26. Transpose a 2D array.
27. Add a new axis to a 1D array to make it 2D.
28. Repeat each element of an array three times.
29. Tile a 1D array to create a 2D matrix.
30. Swap two axes of a 3D array.

Mathematical Operations

31. Perform element-wise addition of two arrays.


32. Perform matrix multiplication of two 2D arrays.
33. Calculate the dot product of two 1D arrays.
34. Compute the sum of all elements in a 2D array.
35. Find the mean and standard deviation of an array.
36. Calculate the cumulative sum of elements in an array.
37. Compute the element-wise square root of an array.
38. Find the index of the maximum value in a 1D array.
39. Calculate the determinant of a 2x2 matrix.
40. Compute the eigenvalues of a given matrix.
Statistical Operations

41. Find the median of a NumPy array.


42. Calculate the correlation coefficient of two arrays.
43. Compute the variance of an array.
44. Determine the percentile of an array at 50%.
45. Generate a histogram of random values using NumPy.
46. Find the mode of a given array.
47. Calculate the covariance matrix of a dataset.
48. Identify the unique elements in an array.
49. Count the frequency of each element in an array.
50. Create a normalized version of an array.

Random Numbers

51. Generate a 1D array of 5 random integers between 0 and 50.


52. Shuffle the elements of an array.
53. Generate a random sample of size 10 from a uniform distribution.
54. Create a random 3x3 matrix with values between 0 and 1.
55. Generate random numbers with a fixed seed.
56. Create a random permutation of numbers from 1 to 10.
57. Generate 100 random values from a normal distribution with mean 0 and std 1.
58. Simulate a coin toss using NumPy.
59. Generate a random 4x4 array of booleans.
60. Create a random integer array of shape 5x5.

File Operations

61. Save a NumPy array to a .npy file.


62. Load a NumPy array from a .npy file.
63. Save a 2D array to a text file.
64. Read data from a CSV file into a NumPy array.
65. Save a NumPy array to a CSV file.
66. Load a text file into a NumPy array while skipping the first row.
67. Save a NumPy array with headers to a CSV file.
68. Load data from a compressed .npz file.
69. Append new data to an existing NumPy array saved in a file.
70. Convert a NumPy array to a Pandas DataFrame.

Linear Algebra

71. Solve a system of linear equations using NumPy.


72. Compute the inverse of a square matrix.
73. Calculate the rank of a matrix.
74. Perform singular value decomposition (SVD) on a matrix.
75. Compute the QR decomposition of a matrix.
76. Find the trace of a matrix.
77. Check if a matrix is symmetric.
78. Compute the outer product of two vectors.
79. Calculate the Frobenius norm of a matrix.
80. Determine if a matrix is positive definite.

Advanced Array Operations

81. Create a 5x5 array with a border of 1 and inner values of 0.


82. Replace all NaN values in an array with zero.
83. Create a checkerboard pattern using NumPy.
84. Find the nearest value in an array to a given scalar.
85. Normalize a 2D array along the rows.
86. Compute the gradient of an array.
87. Perform a 2D convolution operation using NumPy.
88. Sort a 1D array in descending order.
89. Find the pair of indices of the maximum value in a 2D array.
90. Identify all local maxima in a 1D array.

Performance Optimization

91. Vectorize a Python function using numpy.vectorize().


92. Compare the execution time of a NumPy operation with a Python loop.
93. Perform batch operations on arrays using broadcasting.
94. Use numpy.ufunc to apply a custom function element-wise.
95. Optimize memory usage for large arrays using numpy.memmap.
96. Avoid explicit loops by using NumPy built-in functions.
97. Create a custom ufunc using numpy.frompyfunc().
98. Perform element-wise comparison of two large arrays efficiently.
99. Identify performance bottlenecks in NumPy code.
100. Use NumPy with GPU acceleration libraries like CuPy for large datasets.

Practical Questions-

Basics of pandas

1. How do you create a pandas DataFrame from a dictionary?


2. Create a pandas Series from a list.
3. Load a CSV file into a pandas DataFrame.
4. Display the first 10 rows of a DataFrame.
5. Display the last 5 rows of a DataFrame.
6. How do you get the shape of a DataFrame?
7. Check the data types of all columns in a DataFrame.
8. Rename a column in a DataFrame.
9. Convert a pandas Series to a NumPy array.
10. Check for missing values in a DataFrame.

Data Selection

11. Select a specific column from a DataFrame.


12. Select multiple columns from a DataFrame.
13. Retrieve a specific row using its index.
14. Retrieve a subset of rows using slicing.
15. Filter rows based on a condition.
16. Filter rows where a column's value is greater than a given number.
17. Retrieve rows where multiple conditions are met.
18. Select rows by index labels using loc.
19. Select rows by index positions using iloc.
20. Retrieve a specific cell value using at or iat.

Data Cleaning

21. Replace all NaN values in a column with a specific value.


22. Drop rows with missing values.
23. Drop columns with missing values.
24. Fill missing values in a DataFrame using forward fill.
25. Remove duplicate rows from a DataFrame.
26. Standardize column names by converting them to lowercase.
27. Strip whitespace from column names.
28. Convert a column's data type to datetime.
29. Remove outliers from a column based on the interquartile range.
30. Replace specific values in a column with another value.

Data Transformation

31. Add a new column to a DataFrame.


32. Modify an existing column by applying a function.
33. Create a new column based on conditions using np.where.
34. Calculate the cumulative sum of a column.
35. Normalize a column to have values between 0 and 1.
36. Create a new column by combining two existing columns.
37. Split a column containing strings into multiple columns.
38. Convert a categorical column into dummy/indicator variables.
39. Group data by a column and calculate the mean of each group.
40. Pivot a DataFrame to reshape it.

Data Aggregation

41. Calculate the sum of a specific column.


42. Calculate the mean of all numeric columns.
43. Find the median of a column grouped by another column.
44. Count the number of rows in each group.
45. Find the maximum value in a column grouped by another column.
46. Calculate the percentage contribution of each row in a column.
47. Aggregate multiple functions (e.g., sum, mean) for each group.
48. Apply a custom aggregation function to a group.
49. Sort a DataFrame by a specific column.
50. Sort a DataFrame by multiple columns.

Merging and Joining

51. Merge two DataFrames on a common column.


52. Perform a left join between two DataFrames.
53. Perform an inner join between two DataFrames.
54. Perform a right join between two DataFrames.
55. Concatenate two DataFrames vertically.
56. Concatenate two DataFrames horizontally.
57. Append one DataFrame to another.
58. Remove rows that exist in both DataFrames.
59. Perform a Cartesian product of two DataFrames.
60. Merge two DataFrames with different column names.

File Operations

61. Save a DataFrame to a CSV file.


62. Load data from an Excel file into a DataFrame.
63. Save a DataFrame to an Excel file with multiple sheets.
64. Read data from a JSON file into a DataFrame.
65. Write a DataFrame to a JSON file.
66. Load a DataFrame from a SQL database.
67. Write a DataFrame to a SQL database.
68. Save a DataFrame to a pickle file.
69. Load a DataFrame from a pickle file.
70. Write a DataFrame to a compressed CSV file.
Date and Time

71. Convert a column to a datetime object.


72. Extract the year from a datetime column.
73. Extract the month from a datetime column.
74. Extract the day of the week from a datetime column.
75. Filter rows based on a date range.
76. Calculate the difference between two datetime columns.
77. Add 7 days to all dates in a datetime column.
78. Group data by month and calculate the sum of a column.
79. Resample time-series data to a weekly frequency.
80. Convert a datetime column to a Unix timestamp.

Visualization

81. Create a bar plot from a DataFrame.


82. Create a line plot for a time-series column.
83. Generate a histogram of a numeric column.
84. Create a scatter plot between two columns.
85. Visualize missing data using a heatmap.
86. Create a pie chart from a categorical column.
87. Plot the cumulative sum of a column.
88. Visualize the distribution of a column using a boxplot.
89. Create a correlation heatmap for all numeric columns.
90. Save a plot to an image file.

Performance Optimization

91. Optimize memory usage of a DataFrame by changing data types.


92. Use vectorized operations to calculate a new column instead of a loop.
93. Filter rows using query() for better performance.
94. Use applymap() to apply a function element-wise to an entire DataFrame.
95. Use categorical data types to reduce memory usage.
96. Profile the execution time of pandas operations.
97. Load a large dataset in chunks using read_csv().
98. Perform parallelized operations on a DataFrame.
99. Use .eval() for efficient computation of expressions.
100. Optimize joins by setting the index before merging.

Theoritical Questions-

Basics of pandas

1. What is pandas in Python, and why is it used?


2. Differentiate between a pandas Series and a pandas DataFrame.
3. What are the key features of pandas?
4. Explain the advantages of using pandas over lists or dictionaries in Python.
5. What are the primary data structures in pandas?
6. How does pandas handle missing data?
7. What is the purpose of the pd.read_csv() function?
8. Explain the difference between pd.read_csv() and pd.read_excel().
9. What is the difference between loc[] and iloc[] in pandas?
10. How does pandas differ from NumPy?

Data Structures

11. What is a pandas Series, and how is it different from a NumPy array?
12. What is a pandas DataFrame?
13. How do you create a DataFrame from a dictionary?
14. Can a DataFrame contain mixed data types?
15. What is an Index in pandas?
16. Explain the concept of hierarchical indexing in pandas.
17. What are MultiIndex objects in pandas?
18. How does pandas handle labeled data?
19. What is the difference between .at[] and .iat[]?
20. What are pandas Panel data structures, and are they still in use?

Data Operations

21. What is the purpose of the head() and tail() functions?


22. How do you check the dimensions of a DataFrame?
23. What is the use of the info() method in pandas?
24. How can you rename columns in a DataFrame?
25. What is the difference between drop() and del in pandas?
26. How do you sort a DataFrame by column values?
27. What is the purpose of the reset_index() function?
28. Explain the difference between apply(), map(), and applymap() in pandas.
29. How do you filter rows in a DataFrame based on a condition?
30. What is the use of the query() method in pandas?

Missing Data

31. How does pandas represent missing data?


32. What is the difference between isnull() and notnull()?
33. How do you drop rows with missing values in pandas?
34. Explain the fillna() method in pandas.
35. What is the purpose of the interpolate() method?
36. How can you replace specific values in a DataFrame?
37. What strategies can you use to handle missing data in pandas?
38. How does pandas handle missing data in time-series data?
39. Can you filter out rows where all columns are NaN?
40. What is the purpose of the dropna() method?

Merging and Joining

41. What is the difference between merge() and concat() in pandas?


42. Explain the types of joins available in pandas.
43. How does the join() method differ from merge()?
44. What is the use of the concat() function in pandas?
45. How can you append rows to a DataFrame?
46. What happens if you merge two DataFrames with duplicate column names?
47. What is the significance of the on parameter in merge()?
48. How can you combine multiple DataFrames horizontally?
49. Explain the ignore_index parameter in concatenation.
50. How do you handle missing keys when joining DataFrames?

GroupBy and Aggregation

51. What is the purpose of the groupby() function in pandas?


52. How does the groupby() method work internally?
53. What is the difference between agg() and apply() in pandas?
54. How do you calculate the sum of a column grouped by another column?
55. What is the purpose of the transform() function?
56. Explain the concept of split-apply-combine in pandas.
57. How do you group by multiple columns in pandas?
58. What is the purpose of the size() method in groupby objects?
59. How does the describe() method work on grouped data?
60. What is the difference between filter() and apply() in groupby objects?

File Operations

61. How do you read a CSV file into a DataFrame?


62. What is the purpose of the to_csv() method?
63. How can you load data from an Excel file into a DataFrame?
64. Explain the difference between read_json() and to_json().
65. What is the purpose of the read_sql() method?
66. How do you save a DataFrame to a pickle file?
67. What is the use of the chunksize parameter in read_csv()?
68. How can you skip specific rows while reading a file in pandas?
69. What is the purpose of the compression parameter in file operations?
70. How do you read data from a remote URL using pandas?
Date and Time

71. How does pandas handle date and time data?


72. What is the purpose of the to_datetime() function?
73. How do you extract year, month, and day from a datetime column?
74. What is the use of the dt accessor in pandas?
75. How do you filter rows based on a date range?
76. What is the purpose of the resample() method?
77. How do you handle time zones in pandas?
78. Explain the difference between freq and period in time-series data.
79. What is the purpose of the asfreq() method?
80. How can you calculate the difference between two datetime columns?

Advanced Features

81. What are categorical data types in pandas?


82. How do you optimize memory usage in a DataFrame?
83. What is the difference between a sparse DataFrame and a regular DataFrame?
84. How do you use eval() in pandas?
85. What is the purpose of the pivot_table() method?
86. How does pandas handle duplicate rows?
87. Explain the difference between stack() and unstack().
88. What is the purpose of the melt() function?
89. How do you create a custom function and apply it to a DataFrame?
90. What is the difference between merge_asof() and merge()?

Performance Optimization

91. How can you improve the performance of pandas operations?


92. What is vectorization in pandas, and why is it important?
93. Explain the use of numexpr in pandas operations.
94. How do you load large datasets efficiently using pandas?
95. What is the purpose of the memory_usage() method?
96. How can you reduce the memory usage of a DataFrame?
97. What are the advantages of using .loc[] over traditional slicing?
98. How does pandas leverage NumPy for performance?
99. What is the purpose of the parallelize() function in pandas extensions?
100. How do you profile the performance of pandas operations?
Matplotlib Theoritical

Basics of Matplotlib

1. What is Matplotlib, and why is it used?


2. What are the main features of Matplotlib?
3. What is the difference between Matplotlib and Seaborn?
4. Explain the role of the pyplot module in Matplotlib.
5. What is the purpose of the plt.show() function?
6. How does Matplotlib handle visualization in Jupyter Notebooks?
7. What are the different backends available in Matplotlib?
8. Explain the difference between a figure and an axis in Matplotlib.
9. What is the purpose of the plt.figure() function?
10. How does Matplotlib handle multiple plots in a single figure?

Plotting Basics

11. What is the purpose of the plt.plot() function?


12. How do you add labels to the x-axis and y-axis in a plot?
13. How can you add a title to a plot in Matplotlib?
14. What is the purpose of the legend() function in Matplotlib?
15. How do you change the size of a figure in Matplotlib?
16. What are the default data formats supported by Matplotlib for plotting?
17. How do you customize the color of a line in a plot?
18. What is the purpose of the marker parameter in the plt.plot() function?
19. Explain the difference between plt.plot() and plt.scatter().
20. How can you save a plot as an image file?

Axes and Subplots

21. What is an axis in Matplotlib?


22. How do you create multiple subplots in a single figure?
23. Explain the difference between plt.subplot() and plt.subplots().
24. How can you share x-axis or y-axis limits across subplots?
25. What is the purpose of the GridSpec module in Matplotlib?
26. How do you adjust the spacing between subplots?
27. How can you create nested subplots in Matplotlib?
28. Explain the difference between tight_layout() and constrained_layout().
29. How do you remove axes from a plot?
30. How can you create a polar plot in Matplotlib?

Customizing Plots
31. What are the common ways to customize plots in Matplotlib?
32. How do you change the font size of labels and titles in a plot?
33. What is the purpose of the rcParams module in Matplotlib?
34. How can you set the limits of the x-axis and y-axis?
35. What is the purpose of the plt.xlim() and plt.ylim() functions?
36. How do you add grid lines to a plot?
37. What is the use of the alpha parameter in Matplotlib?
38. How can you change the style of lines in a plot?
39. Explain the difference between set_xlabel() and plt.xlabel().
40. How do you add annotations to a plot?

Advanced Plots

41. What is the difference between plt.bar() and plt.barh()?


42. How do you create a histogram in Matplotlib?
43. What is the purpose of the bins parameter in plt.hist()?
44. How can you create a pie chart in Matplotlib?
45. Explain the use of the explode parameter in plt.pie().
46. What is the difference between plt.scatter() and plt.hexbin()?
47. How do you create a boxplot in Matplotlib?
48. What is the purpose of the violinplot() function?
49. How do you create a heatmap in Matplotlib?
50. Explain the use of the contour() and contourf() functions.

Colormaps

51. What are colormaps in Matplotlib?


52. How do you change the colormap of a plot?
53. What is the difference between sequential, diverging, and qualitative colormaps?
54. How can you reverse a colormap in Matplotlib?
55. Explain the use of the colorbar() function.
56. What is the purpose of the cmap parameter in plotting functions?
57. How do you visualize data with a custom colormap?
58. What are perceptually uniform colormaps, and why are they important?
59. How do you create a scatter plot with a colormap?
60. How can you normalize data for use with colormaps?

3D Plotting

61. How do you create 3D plots in Matplotlib?


62. What is the purpose of the Axes3D module?
63. How can you create a 3D scatter plot?
64. Explain the use of the plot_surface() function.
65. What is the purpose of the wireframe() function in 3D plotting?
66. How do you add a color bar to a 3D plot?
67. What are the limitations of 3D plotting in Matplotlib?
68. How can you rotate a 3D plot for better visualization?
69. What is the purpose of the elev and azim parameters in 3D plots?
70. How do you create 3D bar plots in Matplotlib?

Legends and Labels

71. How do you add a legend to a plot?


72. What is the purpose of the loc parameter in legends?
73. How can you customize the font size of a legend?
74. What is the use of the bbox_to_anchor parameter in legends?
75. How do you create a custom legend in Matplotlib?
76. What is the purpose of the label parameter in plotting functions?
77. How can you display a legend outside the plot area?
78. Explain the difference between automatic and manual legends.
79. How do you add multiple legends to a single plot?
80. What is the purpose of the handlelength parameter in legends?

Interactivity

81. What are interactive plots in Matplotlib?


82. How do you enable interactive mode in Matplotlib?
83. What is the purpose of the plt.pause() function?
84. How can you use the mpl_connect() method for interactivity?
85. Explain the use of widgets in Matplotlib.
86. How do you create zoomable plots in Matplotlib?
87. What is the purpose of the Cursor widget?
88. How do you create a draggable annotation in Matplotlib?
89. What is the use of the pick_event in interactive plots?
90. How can you update a plot dynamically?

Performance Optimization

91. What are the common performance issues in Matplotlib?


92. How can you optimize the rendering of large datasets in Matplotlib?
93. What is the purpose of the agg backend in Matplotlib?
94. How does vectorized rendering improve performance?
95. What is the difference between rasterized and vectorized plots?
96. How can you reduce the memory usage of Matplotlib plots?
97. What is the purpose of the blit parameter in animations?
98. How do you use Matplotlib with other visualization libraries for better performance?
99. What is the role of caching in Matplotlib?
100. How can you profile the performance of a Matplotlib script?

Matplotlib Practical

Basic Plotting

1. Create a simple line plot of y=x2y = x^2y=x2 for xxx ranging from -10 to 10.
2. Plot a sine wave using Matplotlib for xxx values between 0 and 2π2\pi2π.
3. Add labels to the x-axis and y-axis and a title to a plot.
4. Customize a line plot with a dashed line style and red color.
5. Plot multiple lines on the same graph with different colors and legends.
6. Save a plot as a PNG file.
7. Create a scatter plot for two random arrays of size 50.
8. Adjust the size of the figure for a plot.
9. Create a plot with grid lines.
10. Draw a vertical and horizontal line on a plot at specific points.

Subplots

11. Create two subplots in a single row.


12. Create a 2x2 grid of subplots.
13. Share the x-axis across all subplots in a figure.
14. Adjust the spacing between subplots.
15. Plot different types of charts (line, bar, scatter, etc.) in subplots.
16. Add a common title for all subplots.
17. Remove the axes for a specific subplot.
18. Create subplots with different sizes using gridspec.
19. Use plt.subplot() to create a 3x1 layout and plot data.
20. Combine subplots and a large central plot in a single figure.

Customizing Plots

21. Change the font size of axis labels and titles.


22. Customize the color of grid lines in a plot.
23. Rotate the x-axis tick labels by 45 degrees.
24. Add a text annotation to a specific point on a plot.
25. Change the style of a plot using Matplotlib’s built-in styles.
26. Customize the marker style and size in a scatter plot.
27. Add a shadow to a bar chart.
28. Use a logarithmic scale for the y-axis in a plot.
29. Change the range of the x-axis and y-axis.
30. Add multiple legends to a single plot.
Advanced Plots

31. Create a bar chart showing sales data for different products.
32. Create a horizontal bar chart.
33. Plot a histogram for a random dataset of size 1000.
34. Create a pie chart with labels and percentages.
35. Add an exploded slice to a pie chart.
36. Plot a boxplot for a dataset with outliers.
37. Create a violin plot for two datasets.
38. Generate a heatmap from a 2D array.
39. Create a contour plot for z=x2+y2z = x^2 + y^2z=x2+y2.
40. Create a filled contour plot.

Colormaps

41. Apply a colormap to a scatter plot.


42. Create a heatmap with a diverging colormap.
43. Reverse the colormap of a plot.
44. Normalize data before applying a colormap.
45. Use a custom colormap in a plot.
46. Add a color bar to a heatmap.
47. Create a scatter plot where the size and color of points depend on data values.
48. Use a colormap to represent a third dimension in a 2D plot.
49. Plot data with a perceptually uniform colormap.
50. Create a gradient background using a colormap.

3D Plotting

51. Create a 3D scatter plot.


52. Plot a 3D surface for z=sin⁡(x)⋅cos⁡(y)z = \sin(x) \cdot \cos(y)z=sin(x)⋅cos(y).
53. Create a 3D bar plot.
54. Rotate a 3D plot for better visualization.
55. Add a color bar to a 3D surface plot.
56. Plot a wireframe for z=x2−y2z = x^2 - y^2z=x2−y2.
57. Create a 3D contour plot.
58. Customize the view angle of a 3D plot.
59. Add labels to axes in a 3D plot.
60. Create a 3D line plot.

Legends and Annotations

61. Add a legend to a plot with custom labels.


62. Position a legend outside the plot area.
63. Change the font size and color of a legend.
64. Add an annotation to mark the maximum value in a plot.
65. Create a custom legend with unique markers.
66. Add multiple legends to a single figure.
67. Highlight a specific region in a plot with annotations.
68. Use a draggable legend in a plot.
69. Add arrows to annotations for better clarity.
70. Customize the legend background color and border.

Interactive Plots

71. Enable interactive mode in Matplotlib.


72. Create a plot that updates dynamically using FuncAnimation.
73. Add a slider to adjust the parameters of a plot.
74. Use a button widget to switch between plots.
75. Implement zoom functionality in a plot.
76. Capture mouse click events on a plot.
77. Add a draggable text annotation to a plot.
78. Create a real-time updating plot using Matplotlib.
79. Use the mpl_connect() method to handle keyboard events.
80. Implement a simple interactive dashboard with sliders and buttons.

File Operations

81. Save a plot as a PDF file.


82. Save a figure with a transparent background.
83. Export a plot with high DPI for publication.
84. Save multiple plots into a single PDF file.
85. Load data from a CSV file and visualize it with Matplotlib.
86. Save a plot as an SVG file.
87. Save a plot with specific dimensions.
88. Export a plot with metadata included.
89. Save a plot in multiple formats (PNG, PDF, SVG) in one script.
90. Add a watermark to a plot before saving.

Performance Optimization

91. Optimize a plot for large datasets using downsampling.


92. Use vectorized operations to improve plotting speed.
93. Plot a large dataset efficiently using rasterized rendering.
94. Reduce memory usage for a figure with multiple subplots.
95. Use the agg backend for faster rendering.
96. Profile the time taken to generate a plot.
97. Use blit to optimize animations.
98. Create a lightweight plot for real-time data visualization.
99. Combine Matplotlib with NumPy for optimized calculations.
100. Generate multiple plots in parallel using multiprocessing.

Seaborn Theoretical

Basics of Seaborn

1. What is Seaborn, and how does it differ from Matplotlib?


2. What are the main advantages of using Seaborn over Matplotlib?
3. What types of visualizations can be created using Seaborn?
4. How does Seaborn simplify statistical plotting?
5. What is the relationship between Seaborn and Pandas?
6. What are the dependencies required to use Seaborn?
7. What is the default data structure used by Seaborn for plotting?
8. How does Seaborn handle categorical data visualization?
9. What are the default styles available in Seaborn?
10. How does Seaborn handle themes and aesthetics compared to Matplotlib?

Data Handling

11. What types of datasets are supported by Seaborn?


12. How does Seaborn use Pandas DataFrames for plotting?
13. Explain the concept of “long-form” and “wide-form” data in Seaborn.
14. How do you specify data for Seaborn plots using column names?
15. What is the purpose of the hue parameter in Seaborn?
16. How does Seaborn handle missing data in datasets?
17. Explain the role of the palette parameter in Seaborn.
18. How can you map different levels of a categorical variable to colors?
19. What is the purpose of the order and hue_order parameters?
20. How does Seaborn manage grouping in categorical plots?

Styling and Themes

21. What are the default styles in Seaborn?


22. How do you change the overall theme of a Seaborn plot?
23. Explain the purpose of the set_style() function.
24. What are the differences between the whitegrid and darkgrid styles?
25. How do you adjust the context of a Seaborn plot?
26. What is the purpose of the set_context() function?
27. How can you customize the font size and style in Seaborn?
28. Explain the role of the rc parameter in Seaborn.
29. How does Seaborn integrate with Matplotlib for styling?
30. What is the purpose of the despine() function?
Categorical Plots

31. What are categorical plots in Seaborn?


32. How does the catplot() function work in Seaborn?
33. What is the difference between stripplot() and swarmplot()?
34. Explain the purpose of the boxplot() function in Seaborn.
35. What is the difference between boxplot() and violinplot()?
36. How does the barplot() function handle statistical aggregation?
37. What is the purpose of the countplot() function?
38. How do you add jitter to a stripplot()?
39. Explain the use of the dodge parameter in categorical plots.
40. What is the difference between pointplot() and lineplot()?

Relational Plots

41. What are relational plots in Seaborn?


42. Explain the difference between scatterplot() and lineplot().
43. How does the relplot() function differ from scatterplot()?
44. What is the purpose of the size parameter in scatterplot()?
45. How do you use the style parameter in relational plots?
46. Explain the role of the col and row parameters in relplot().
47. How does Seaborn handle overlapping points in scatter plots?
48. What is the purpose of the hue_norm parameter in relational plots?
49. How do you customize markers in scatterplot()?
50. Explain the use of the legend parameter in relational plots.

Distribution Plots

51. What are distribution plots in Seaborn?


52. Explain the difference between histplot() and kdeplot().
53. What is the purpose of the distplot() function, and why is it deprecated?
54. How does the rugplot() function work?
55. What is the purpose of the bins parameter in histplot()?
56. Explain the role of the shade parameter in kdeplot().
57. How do you plot a cumulative distribution function (CDF) in Seaborn?
58. What is the purpose of the stat parameter in histplot()?
59. How does Seaborn handle multiple distributions in a single plot?
60. Explain the use of the fill parameter in distribution plots.

Matrix Plots
61. What are matrix plots in Seaborn?
62. Explain the purpose of the heatmap() function.
63. How do you customize the color map in heatmap()?
64. What is the role of the annot parameter in heatmap()?
65. How do you normalize data for a heatmap in Seaborn?
66. Explain the purpose of the cbar parameter in heatmap().
67. How do you add labels to rows and columns in a heatmap?
68. What is the purpose of the clustermap() function?
69. Explain the difference between heatmap() and clustermap().
70. How does Seaborn handle hierarchical clustering in clustermap()?

Pairwise and Joint Plots

71. What is the purpose of the pairplot() function in Seaborn?


72. How does Seaborn handle pairwise relationships in pairplot()?
73. Explain the role of the diag_kind parameter in pairplot().
74. How do you customize the plots in the diagonal of a pairplot()?
75. What is the purpose of the jointplot() function?
76. Explain the difference between kind='scatter' and kind='kde' in jointplot().
77. How do you add a regression line to a jointplot()?
78. What is the purpose of the marginal_kws parameter in jointplot()?
79. How does Seaborn handle multiple variables in pairplot()?
80. What are the limitations of pairplot() for large datasets?

Regression Plots

81. What are regression plots in Seaborn?


82. Explain the purpose of the regplot() function.
83. How does the lmplot() function differ from regplot()?
84. What is the purpose of the order parameter in regplot()?
85. How do you add a confidence interval to a regression line?
86. Explain the role of the ci parameter in regression plots.
87. How do you handle categorical variables in lmplot()?
88. What is the purpose of the logistic parameter in regression plots?
89. How does Seaborn handle multiple regression lines in a single plot?
90. What are the limitations of regression plots in Seaborn?

Customizations and Integration

91. How do you integrate Seaborn with Matplotlib for further customization?
92. Explain the use of the FacetGrid class in Seaborn.
93. What is the purpose of the hue parameter in FacetGrid?
94. How do you map a custom function to a Seaborn grid?
95. How does Seaborn handle custom color palettes?
96. Explain the role of the sns.set_palette() function.
97. How do you create a custom colormap for Seaborn plots?
98. What is the purpose of the as_cmap parameter in Seaborn?
99. How do you handle large datasets efficiently in Seaborn?
100. What are the common performance issues when using Seaborn?

Seaborn Practical

Basic Seaborn Usage

1. Create a simple line plot using Seaborn with a dataset of your choice.
2. Load the built-in tips dataset and display its first 5 rows.
3. Create a scatter plot to visualize total_bill vs. tip from the tips dataset.
4. Add a regression line to a scatter plot using regplot().
5. Customize the color and size of markers in a scatter plot.
6. Create a bar plot to show the average total_bill for each day in the tips dataset.
7. Add error bars to a bar plot using the ci parameter.
8. Create a histogram to visualize the distribution of total_bill.
9. Adjust the number of bins in a histogram.
10. Create a KDE plot for the tip column in the tips dataset.

Categorical Plots

11. Create a boxplot to visualize the distribution of total_bill across different days.
12. Add a swarmplot over a boxplot for better visualization of individual data points.
13. Create a violin plot to compare the total_bill across different days.
14. Use split=True in a violin plot to show distributions for sex.
15. Create a count plot to show the number of observations for each day.
16. Create a strip plot for total_bill grouped by day.
17. Add jitter to a strip plot to avoid overlapping points.
18. Create a bar plot with custom colors for each bar.
19. Use dodge=True to separate categories in a categorical plot.
20. Create a point plot for total_bill across day with sex as hue.

Relational Plots

21. Create a relational plot using relplot() for total_bill vs. tip.
22. Use hue to differentiate sex in a relational plot.
23. Add size to represent the size of data points in a scatter plot.
24. Create a line plot for a time series dataset.
25. Add style to differentiate categories in a line plot.
26. Use col to create subplots for each day in a relational plot.
27. Combine col and row to create a grid of subplots.
28. Add a legend to a scatter plot for better understanding.
29. Change the size of markers in a relational plot.
30. Use a logarithmic scale for one of the axes in a scatter plot.

Distribution Plots

31. Create a histogram for total_bill with a KDE overlay.


32. Plot a KDE plot for tip with shade=True.
33. Create a rug plot for the total_bill column.
34. Combine a rug plot with a KDE plot.
35. Plot a cumulative histogram for total_bill.
36. Use multiple="stack" to create stacked histograms for sex.
37. Create a bivariate KDE plot for total_bill and tip.
38. Add a scatter plot to a bivariate KDE plot.
39. Plot a KDE plot with custom bandwidth.
40. Create a histogram with different colors for each category in sex.

Matrix Plots

41. Create a heatmap for a correlation matrix of the tips dataset.


42. Annotate values in a heatmap.
43. Change the colormap of a heatmap.
44. Normalize the data in a heatmap.
45. Add labels to rows and columns in a heatmap.
46. Create a clustered heatmap using clustermap().
47. Change the method of clustering in clustermap().
48. Use a diverging colormap in a heatmap.
49. Plot a heatmap with specific color limits.
50. Add a color bar to a heatmap.

Pairwise and Joint Plots

51. Create a pair plot for the tips dataset.


52. Customize the diagonal plots in a pair plot.
53. Add hue to a pair plot to differentiate sex.
54. Use a KDE plot on the diagonal of a pair plot.
55. Create a joint plot for total_bill vs. tip.
56. Change the kind of a joint plot to kde.
57. Add marginal histograms to a joint plot.
58. Customize the scatter plot in a joint plot.
59. Use a hexbin plot in a joint plot.
60. Create a joint plot with a regression line.
Regression Plots

61. Create a regression plot for total_bill vs. tip.


62. Add confidence intervals to a regression plot.
63. Use a higher-order polynomial regression in regplot().
64. Add hue to show different regression lines for categories.
65. Use lmplot() to create a regression plot with subplots.
66. Create a logistic regression plot.
67. Plot a regression line with a specific x_jitter.
68. Use scatter_kws to customize the scatter points in a regression plot.
69. Plot multiple regression lines in a single plot.
70. Remove the regression line and show only scatter points.

FacetGrid

71. Create a FacetGrid with subplots for each day in the tips dataset.
72. Map a scatter plot to a FacetGrid.
73. Add a KDE plot to a FacetGrid.
74. Use col_wrap to limit the number of columns in a FacetGrid.
75. Customize the titles of subplots in a FacetGrid.
76. Add a legend to a FacetGrid.
77. Use hue in a FacetGrid to differentiate categories.
78. Plot different types of plots in a single FacetGrid.
79. Customize the size of subplots in a FacetGrid.
80. Create a grid of subplots with different variables.

Customizations

81. Change the overall theme of Seaborn plots.


82. Use set_style() to apply the whitegrid style.
83. Adjust the context of a plot using set_context().
84. Customize the font size and style in a plot.
85. Change the palette of a plot to a custom color palette.
86. Use set_palette() to apply a specific color scheme.
87. Add grid lines to a plot.
88. Remove the top and right spines of a plot.
89. Use despine() to adjust the appearance of spines.
90. Change the aspect ratio of a plot.

Integration and Saving

91. Save a Seaborn plot as a PNG file.


92. Save a plot with a transparent background.
93. Export a plot with high DPI for publication.
94. Use Seaborn with Matplotlib to add custom annotations.
95. Add a secondary y-axis to a Seaborn plot using Matplotlib.
96. Combine Seaborn and Matplotlib to create complex visualizations.
97. Save multiple Seaborn plots into a single PDF file.
98. Add a watermark to a Seaborn plot.
99. Use a custom function to modify a Seaborn grid.
100. Combine Seaborn with Plotly or other libraries for interactive visualizations.

You might also like