w3resource

Pandas and NumPy Exercises, Practice, Solution for Data Analysis

Python Pandas Numpy [37 exercises with solution]

[An editor is available at the bottom of the page to write and execute the scripts.  Go to the editor]

1. Load a CSV file into a Pandas DataFrame.
Click me to see the sample solution

2. Create a DataFrame from a NumPy array with custom column names.
Click me to see the sample solution

3. Select rows from a DataFrame based on multiple conditions.
Click me to see the sample solution

4. Select the first and last 7 rows of a Pandas DataFrame.
Click me to see the sample solution

5. Filter rows based on a condition in a specific column in a Pandas DataFrame.
Click me to see the sample solution

6. Create a new column in a Pandas DataFrame based on the result of a NumPy operation.
Click me to see the sample solution

7. Merge two Pandas DataFrames based on a common column.
Click me to see the sample solution

8. Extract rows from a Pandas DataFrame where a specific column's values are in a given NumPy array.
Click me to see the sample solution

9. Perform element-wise addition of a NumPy array and a Pandas DataFrame column.
Click me to see the sample solution

10. Apply a NumPy function to a Pandas DataFrame column.
Click me to see the sample solution

11. Calculate the correlation matrix for a Pandas DataFrame.
Click me to see the sample solution

12. Calculate the cumulative sum of a NumPy array and store the results in a new Pandas DataFrame column.
Click me to see the sample solution

13. Group a Pandas DataFrame by a column and calculate the mean of another column.
Click me to see the sample solution

14. Reshape a Pandas DataFrame using the pivot_table function.
Click me to see the sample solution

15. Replace missing values in a Pandas DataFrame with the mean of the column.
Click me to see the sample solution

16. Create a histogram of a numerical column using NumPy and Matplotlib.
Click me to see the sample solution

17. Normalize a numerical column in a Pandas DataFrame.
Click me to see the sample solution

18. Remove duplicate rows from a Pandas DataFrame.
Click me to see the sample solution

19. Perform element-wise addition on two NumPy arrays.
Click me to see the sample solution

20. Calculate the dot product of two NumPy arrays.
Click me to see the sample solution

21. Find the index of the maximum and minimum value in a NumPy array.
Click me to see the sample solution

22. Reshape a 1D NumPy array into a 2D array.
Click me to see the sample solution

23. Slice and extract a portion of a NumPy array.
Click me to see the sample solution

24. Concatenate two NumPy arrays vertically.
Click me to see the sample solution

25. Perform matrix multiplication using NumPy.
Click me to see the sample solution

26. Calculate the cumulative sum of a NumPy array.
Click me to see the sample solution

27. Create a NumPy array with random values and find the unique values.
Click me to see the sample solution

28. Sort a Pandas DataFrame by values in a specific column.
Click me to see the sample solution

29. Apply a custom function to each element in a Pandas DataFrame.
Click me to see the sample solution

30. Rename columns in a Pandas DataFrame.
Click me to see the sample solution

31. Create a new DataFrame by transposing an existing one.
Click me to see the sample solution

32. Merge two DataFrames based on multiple columns.
Click me to see the sample solution

33. Aggregate data in a DataFrame by multiple functions.
Click me to see the sample solution

34. Extract the date and time components from a DateTime column.
Click me to see the sample solution

35. Resample time-series data in a DataFrame.
Click me to see the sample solution

36. Perform a rolling calculation on a numerical column in a DataFrame.
Click me to see the sample solution

37. Perform a cross-tabulation between two columns in a DataFrame.
Click me to see the sample solution

Python Code Editor:

More to Come !

Do not submit any solution of the above exercises at here, if you want to contribute go to the appropriate exercise page.

Test your Python skills with w3resource's quiz



Follow us on Facebook and Twitter for latest update.