Pandas Trick Ques
Pandas Trick Ques
2. What is the difference between iloc[] and loc[]? When would you use each?
6. How can you get the number of rows and columns in a DataFrame?
12. How can you fill missing values with the mean of a column?
14. How do you fill missing values forward (propagate the last valid value) in a DataFrame?
15. How do you drop rows that contain missing values in specific columns?
16. How do you fill missing values using different methods for different columns?
17. How do you count the number of missing values in each column?
19. How can you fill missing values with values from another column?
20. How do you drop columns that contain only missing values?
23. How can you use lambda functions to create a new column based on existing columns?
30. How do you map values of a Series to another set of values using map()?
31. How do you group data by a column and calculate the mean for each group?
32. What is the difference between agg() and apply() when using groupby()?
33. How do you group by multiple columns and calculate different aggregates for each group?
34. How can you get the first row of each group in a groupby() operation?
35. How do you perform a custom aggregation on a groupby() object using a lambda function?
36. What is transform() used for in the context of groupby()?
37. How do you use cumsum() to calculate a cumulative sum within each group?
41. What happens if you try to access a column that doesn’t exist using df['column_name']?
43. How do you select all rows where a column value is in a list of values?
44. How do you access a DataFrame cell by row and column names?
45. How can you find the index of the maximum value in a column?
46. How do you select all rows where a column contains a specific substring?
47. How do you select a subset of columns that match a specific pattern (e.g., columns starting with 'A')?
48. What is the difference between df['A'] and df[['A']] when selecting columns?
50. How can you use query() to filter rows based on complex conditions?
51. How do you remove trailing and leading spaces from string columns?
52. How can you replace all occurrences of a string in a column with another string?
54. How do you extract the year, month, and day from a datetime column?
56. How can you split a string column into multiple columns?
57. How do you convert a datetime column into the index of a DataFrame?
61. How do you calculate the correlation between two columns in a DataFrame?
64. How can you add a column with a sequence of numbers to a DataFrame?
65. What is the fastest way to get the top N rows based on a column value?
68. How do you merge two DataFrames with different column names?