Pandas Apply Exercises

See also: Dataframe.apply()

See also: Series.map()



In [ ]:
# 1. import pandas as pd / pd.read_csv() the simple.csv. Get top 3 entries via .head() and assign to df.

In [ ]:
# 2. Define a function that takes an input, prints .name attribute of input, prints type(input) and prints the input.

In [ ]:
# 3. Use the dataframe.apply() method, and supply the function (with no parenthesis) and axis=1

In [ ]:
# 4. Now do it with axis=0. Which one of these does a function by row? Which by column? Significance of .name?

In [ ]:
# 5. Write a function for a row series that gets the date and count and prints "The Count was X on Date X."

In [ ]:
# 6. Write a function that returns a string. Apply this function to your dataframe. What is the result?

In [ ]:
# 7. Use your new function, and assign the returned series it to a new column, df['New Column 1']

In [ ]:
# 8. Write a function that takes a count and adds 5.  Use map() with your function on your df['Count']

In [ ]:
# 9. This returns a series with each value individually altered. Assign the result to df['New Column 2]