Basic Pandas Exercises

See also: 10 Minutes to Pandas



In [ ]:
# 1. import pandas and then import pandas under the alias pd

In [ ]:
# 2. Use the dir() function to inspect some the availible attributes of pd.

In [ ]:
# 3.  Create a dataframe from the CFPB .csv using pd.read_csv(); assign to variable 'df'.

In [ ]:
# 4. Use the dataframe's head() method to get the first 5 samples of df.

In [ ]:
# 5. Use the dtypes attribute to see what datatypes and columns we have in dataframe 'df'.

In [ ]:
# 6. Use the len() function to look at the length of the dataframe.

In [ ]:
# 7. Use the dataframe's sample method to pull a random sample of 50 from the dataframe

In [ ]:
# 8. Get the dataframe 'df' column names

In [ ]:
# 9. Assign the dataframe's index to a variable called 'index'. Get the index values.

In [ ]:
# 10. Create a pandas.Series object with the values [1, 2, 3, 4, 5]. Assign it to varable 's'.

In [ ]:
# 11. Get the mean, median, amd max of series 's'.

In [ ]:
# 12. Use series.plot() method to graph your series after import matplotlib; %matplotlib inline

In [ ]:
# 13. Add multiply each item in you df by 5 and assign to 's2'. Then use the cumsum() method on 's2'.

In [ ]:
# 14. Create a function that adds 2 to a number and prints it. series.map() it.

In [ ]:
# 15. Translate your series into raw numpy values.

In [ ]:
# 16. Use the value_counts() method of the series to see the value counts.

In [ ]:
# 17. Write your data to disk using df.to_csv()

In [ ]:
# 18. Export this notebook using the file menu above.

# This is done via the menu.