Premium project

Writing Functions for Product Analysis

Use coding best practices and functions to improve a script!

Start Project
8 Tasks1,500 XP

Loved by learners at thousands of companies


Project Description

Have you ever started your data analysis and ended up with repetitive code? Repetitive code is a sign that functions are needed. Functions help keep our code flexible, maintainable, and interpretable. Our colleague Brenda, a product analyst, has written a script to pull Net Promotor Score (NPS) survey data from multiple sources to calculate the NPS score. This code works well, but it violates coding best practices, including Don't Repeat Yourself (DRY). Let's take a look at her code and write some functions for Brenda! To complete this project, you need to know how to write functions in Python and how to use pandas for DataFrame manipulation.

Project Tasks

  1. 1
    DRY: Don't repeat yourself
  2. 2
    Verifying the files with the "with" keyword
  3. 3
    Putting it together with nested functions
  4. 4
    Detractors, Passives, and Promoters
  5. 5
    Applying our function to a DataFrame
  6. 6
    Calculating the Net Promoter Score
  7. 7
    Breaking down NPS by source
  8. 8
    Adding docstrings

Technologies

Python Python

Topics

Programming
Lis Sulmont Headshot

Lis Sulmont

Head of Curriculum Expansion at DataCamp

Lis holds a Master's degree in Computer Science from McGill University with a focus on computer science education research and applied machine learning. She's passionate about teaching all things related to data and improving the accessibility of these topics.
See More

What do other learners have to say?

I've used other sites—Coursera, Udacity, things like that—but DataCamp's been the one that I've stuck with.

Devon Edwards Joseph
Lloyds Banking Group

DataCamp is the top resource I recommend for learning data science.

Louis Maiden
Harvard Business School

DataCamp is by far my favorite website to learn from.

Ronald Bowers
Decision Science Analytics, USAA