Appendix 1: Exercises - kode2go/python-pandas GitHub Wiki

  1. Write a Pandas program to create and display a one-dimensional array-like object containing an array of data using Pandas module.

  2. Write a Pandas program to convert a Panda module Series to Python list and it's type.

  3. Write a Pandas program to add, subtract, multiple and divide two Pandas Series. Sample Series: [2, 4, 6, 8, 10], [1, 3, 5, 7, 9]

  4. Write a Pandas program to compare the elements of the two Pandas Series. Sample Series: [2, 4, 6, 8, 10], [1, 3, 5, 7, 10]

  5. Write a Pandas program to convert a dictionary to a Pandas series. Sample Series: Original dictionary: {'a': 100, 'b': 200, 'c': 300, 'd': 400, 'e': 800} Converted series: a 100 b 200 c 300 d 400 e 800 dtype: int64

  6. Write a Pandas program to convert a NumPy array to a Pandas series. Sample Series: NumPy array: [10 20 30 40 50] Converted Pandas series: 0 10 1 20 2 30 3 40 4 50 dtype: int64

  7. Write a Pandas program to change the data type of given a column or a Series. Sample Series: Original Data Series: 0 100 1 200 2 python 3 300.12 4 400 dtype: object Change the said data type to numeric: 0 100.00 1 200.00 2 NaN 3 300.12 4 400.00 dtype: float64

  8. Write a Pandas program to convert the first column of a DataFrame as a Series. Sample Output: Original DataFrame col1 col2 col3 0 1 4 7 1 2 5 5 2 3 6 8 3 4 9 12 4 7 5 1 5 11 0 11 1st column as a Series: 0 1 1 2 2 3 3 4 4 7 5 11 Name: col1, dtype: int64 <class 'pandas.core.series.Series'>

  9. Write a Pandas program to convert a given Series to an array. Sample Output: Original Data Series: 0 100 1 200 2 python 3 300.12 4 400 dtype: object Series to an array ['100' '200' 'python' '300.12' '400']

  10. Write a Pandas program to convert Series of lists to one Series. Sample Output: Original Series of list 0 [Red, Green, White] 1 [Red, Black] 2 [Yellow] dtype: object One Series 0 Red 1 Green 2 White 3 Red 4 Black 5 Yellow dtype: object

  11. Write a Pandas program to sort a given Series. Sample Output: Original Data Series: 0 100 1 200 2 python 3 300.12 4 400 dtype: object 0 100 1 200 3 300.12 4 400 2 python dtype: object

  12. Write a Pandas program to add some data to an existing Series. Sample Output: Original Data Series: 0 100 1 200 2 python 3 300.12 4 400 dtype: object Data Series after adding some data: 0 100 1 200 2 python 3 300.12 4 400 0 500 1 php dtype: object

  13. Write a Pandas program to create a subset of a given series based on value and condition. Sample Output: Original Data Series: 0 0 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10 dtype: int64 Subset of the above Data Series: 0 0 1 1 2 2 3 3 4 4 5 5 dtype: int64

  14. Write a Pandas program to change the order of index of a given series. Sample Output: Original Data Series: A 1 B 2 C 3 D 4 E 5 dtype: int64 Data Series after changing the order of index: B 2 A 1 C 3 D 4 E 5 dtype: int64

  15. Write a Pandas program to create the mean and standard deviation of the data of a given Series. Sample Output: Original Data Series: 0 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 5 10 3 dtype: int64 Mean of the said Data Series: 4.818181818181818 Standard deviation of the said Data Series: 2.522624895547565

  16. Write a Pandas program to get the items of a given series not present in another given series. Sample Output: Original Series: sr1: 0 1 1 2 2 3 3 4 4 5 dtype: int64 sr2: 0 2 1 4 2 6 3 8 4 10 dtype: int64 Items of sr1 not present in sr2: 0 1 2 3 4 5 dtype: int64

  17. Write a Pandas program to get the items which are not common of two given series. Sample Output: Original Series: sr1: 0 1 1 2 2 3 3 4 4 5 dtype: int64 sr2: 0 2 1 4 2 6 3 8 4 10 dtype: int64 Items of a given series not present in another given series: 0 1 2 3 4 5 5 6 6 8 7 10 dtype: int64

  18. Write a Pandas program to compute the minimum, 25th percentile, median, 75th, and maximum of a given series. Sample Output: Original Series: 0 3.000938 1 11.370722 2 14.612143 3 8.990256 4 13.925283 5 12.056875 .... 17 14.118931 18 8.247458 19 5.526727 dtype: float64 Minimum, 25th percentile, median, 75th, and maximum of a given series: [ 3.00093811 8.09463867 10.23353705 12.21537733 14.61214321]

  19. Write a Pandas program to calculate the frequency counts of each unique value of a given series. Sample Output: Original Series: 0 1 1 7 2 1 3 6 4 9 5 1 ... 29 2 30 9 31 1 32 2 33 9 34 2 35 9 36 0 37 0 38 4 39 8 dtype: object Frequency of each unique value of the said series. 0 9 2 7 9 6 1 5 6 3 8 3 7 3 3 2 4 1 5 1 dtype: int64