1. Learn
  2. /
  3. Courses
  4. /
  5. Writing Efficient Code with pandas

Exercise

Transforming values to probabilities

In this exercise, we will apply a probability distribution function to a pandas DataFrame with group related parameters by transforming the tip variable to probabilities.

The transformation will be a exponential transformation. The exponential distribution is defined as

$$ e^{-\lambda * x} * \lambda $$

where λ (lambda) is the mean of the group that the observation x belongs to.

You're going to apply the exponential distribution transformation to the size of each table in the dataset, after grouping the data according to the time of the day the meal took place. Remember to use each group's mean for the value of λ.

In Python, you can use the exponential as np.exp() from the NumPy library and the mean value as .mean().

Instructions

100 XP
  • Define the exponential distribution transformation exp_tr.
  • Group the data according to the time the meal took place.
  • Apply the transformation to the grouped data.