[go: up one dir, main page]

0% found this document useful (0 votes)
27 views8 pages

Pandas Practise Problems

The document outlines a comprehensive set of practice problems for learning and mastering the Pandas library in Python, categorized into beginner, intermediate, advanced, practical/data analysis, expert levels, and specific tasks. Each section includes various tasks such as creating Series and DataFrames, handling missing data, performing data operations, and advanced techniques like merging datasets for machine learning. This structured approach aims to enhance proficiency in data manipulation and analysis using Pandas.

Uploaded by

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

Pandas Practise Problems

The document outlines a comprehensive set of practice problems for learning and mastering the Pandas library in Python, categorized into beginner, intermediate, advanced, practical/data analysis, expert levels, and specific tasks. Each section includes various tasks such as creating Series and DataFrames, handling missing data, performing data operations, and advanced techniques like merging datasets for machine learning. This structured approach aims to enhance proficiency in data manipulation and analysis using Pandas.

Uploaded by

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

PANDAS PRACTISE

PROBLEMS
BY
MUHAMMAD ALI

🟢 BEGINNER LEVEL

1. Pandas Basics
1. Import pandas and print its version.
2. Create a Series from a list.
3. Create a Series with custom index labels.
4. Access the first 5 rows of a Series.
5. Create a DataFrame from a dictionary.
6. Create a DataFrame from a list of lists.
7. Read a CSV file into a DataFrame.
8. Display the shape, columns, and info of a DataFrame.
9. Check the data types of all columns.
10. Rename columns of a DataFrame.

2. Viewing & Selecting Data


11. View the first and last 3 rows using head() and tail().
12. Access a column using dot notation and bracket notation.
13. Select multiple columns from a DataFrame.
14. Select a specific row using loc.
15. Select a row using integer position with iloc.
16. Slice rows by index using loc.
17. Filter rows where a column equals a specific value.
18. Filter rows where a column is greater than a threshold.
19. Use isin() to filter by multiple values.
20. Use boolean conditions to filter multiple columns.

3. DataFrame Operations
21. Add a new column to a DataFrame.
22. Delete a column from a DataFrame.
23. Reorder the columns in a specific order.
24. Change the values in a column conditionally.
25. Replace specific values in a DataFrame.

🟡 INTERMEDIATE LEVEL

4. Handling Missing Data


26. Detect missing values using isnull().
27. Count missing values in each column.
28. Drop rows with any missing values.
29. Fill missing values with zero.
30. Fill missing values using forward fill method.
31. Fill missing values with the mean of the column.
32. Drop columns with all NaN values.
33. Replace NaN values with a custom string.
34. Interpolate missing numeric values.
35. Check for non-null values using notnull().

5. Data Types & Conversion


36. Convert a column to integer type.
37. Convert object (string) columns to datetime.
38. Use astype() to convert types.
39. Detect and convert categories using astype('category').
40. Use apply() with pd.to_numeric() to clean data.

6. Sorting & Ranking


41. Sort DataFrame by a single column.
42. Sort DataFrame by multiple columns.
43. Sort by index.
44. Use rank() to assign ranks.
45. Reset index of a DataFrame.

7. Working with Text Data


46. Convert a string column to lowercase.
47. Remove whitespace from string values.
48. Replace part of string values in a column.
49. Extract substrings using str.slice().
50. Filter rows where string contains a word.

🔵 ADVANCED LEVEL

8. Aggregation & Grouping


51. Use groupby() to calculate mean for each group.
52. Get count of entries per group.
53. Apply multiple aggregation functions (mean, min, max).
54. Use groupby() on multiple columns.
55. Use agg() to apply custom aggregation per column.

9. Time Series Data


56. Convert a column to datetime.
57. Set a datetime column as index.
58. Filter data for a specific date range.
59. Resample time series data by month and calculate mean.
60. Get the weekday from a datetime column.

10. Merging & Joining


61. Merge two DataFrames using merge().
62. Join on multiple keys.
63. Use different join types: inner, left, right, outer.
64. Merge using index instead of columns.
65. Concatenate two DataFrames vertically.

11. Pivoting & Reshaping


66. Create a pivot table from a DataFrame.
67. Use pivot_table() with aggregation.
68. Reshape a DataFrame using melt().
69. Reshape a melted DataFrame back using pivot().
70. Transpose a DataFrame.

12. Indexes & Hierarchical Indexing


71. Set a specific column as index.
72. Reset a DataFrame index.
73. Create a multi-index from columns.
74. Access data from multi-indexed DataFrame.
75. Swap levels in a multi-index.

🟣 PRACTICAL / DATA ANALYSIS

13. Exploratory Data Analysis (EDA)


76. Count unique values in a column.
77. Get summary statistics using describe().
78. Plot histogram of a numeric column.
79. Find correlation between numeric columns.
80. Identify outliers using IQR method.
14. Categorical Data
81. Convert object column to category.
82. Get unique categories and their counts.
83. Sort categorical values.
84. Rename categories.
85. Group data by categorical variables.

15. Window Functions & Rolling


86. Compute rolling mean over a window of 3.
87. Calculate rolling sum for a column.
88. Use expanding window to compute cumulative mean.
89. Use shift() to create lag features.
90. Compare current and previous rows.

16. Custom Functions & Apply


91. Use apply() with a lambda function on rows.
92. Use map() on a Series to transform data.
93. Apply a custom function to each column.
94. Use applymap() on the whole DataFrame.
95. Create a custom scoring function and apply to rows.

🔴 EXPERT LEVEL

17. Data Cleaning & Transformation


96. Remove rows with duplicate values.
97. Drop duplicate rows based on specific columns.
98. Rename multiple columns at once.
99. Strip HTML tags from string column.
100. Extract numeric values from a mixed-type column.

18. MultiFile & Real World I/O


101. Read multiple CSVs and concatenate them.
102. Read Excel file with multiple sheets.
103. Write a DataFrame to CSV without the index.
104. Export DataFrame to Excel.
105. Use chunksize to process large CSV in parts.

19. Performance Optimization


106. Use categorical data type to save memory.
107. Filter large DataFrame efficiently using vectorized logic.
108. Compare performance of apply() vs vectorized operations.
109. Profile memory usage using memory_usage().
110. Use df.query() for faster row filtering.

20. Merging Datasets for ML


111. Merge training and test sets.
112. Fill missing categorical features with mode.
113. One-hot encode a categorical column.
114. Normalize numeric features using MinMax.
115. Encode ordinal features based on order.

21. Advanced Grouping & Pivoting


116. Pivot table with multiple aggregation functions.
117. Use crosstab() to count combinations.
118. Calculate percentage breakdown in groups.
119. Create custom bins using cut() or qcut().
120. Aggregate columns into new KPIs using custom logic.

You might also like