Aan de slagGa gratis aan de slag

Creating a DataFrame for house ads

The house ads team is concerned because they've seen their conversion rate drop suddenly in the past few weeks. In the previous exercises, you confirmed that conversion is down because you noticed a pattern around language preferences.

As a data scientist, it is your job to provide your marketing stakeholders with as specific feedback as possible as to what went wrong to maximize their ability to correct the problem. It is vital that you not only say "looks like there's a language problem," but instead identify what the problem is specifically so that the team doesn't repeat their mistake.

Deze oefening maakt deel uit van de cursus

Analyzing Marketing Campaigns with pandas

Cursus bekijken

Oefeninstructies

  • Use np.where() to create a new column in house_ads called 'is_correct_lang' whose values are 'Yes' if 'language_displayed' is equal to 'language_preferred' and 'No' otherwise.
  • Group by date_served and is_correct_lang to get a daily count of the ads served.

Praktische interactieve oefening

Probeer deze oefening eens door deze voorbeeldcode in te vullen.

# Add the new column is_correct_lang
house_ads['is_correct_lang'] = np.____(
    house_ads['____'] == house_ads['____'], 
    '____', 
    '____')

# Groupby date_served and correct_language
language_check = house_ads.____(____)['____'].____()

# Unstack language_check and fill missing values with 0's
language_check_df = pd.DataFrame(language_check.unstack(level=1)).fillna(0)

# Print results
print(language_check_df)
Code bewerken en uitvoeren