From the course: Vibe Coding for Data Analysts
Unlock this course with a free trial
Join today to access over 25,200 courses taught by industry experts.
Creating derived variables
From the course: Vibe Coding for Data Analysts
Creating derived variables
- When we're vibing, we might need to make changes. As we think about asking questions of our data, we're often faced with creating new variables from the variables that we already have. We might need to lag a variable, find the percent change from one timeframe to another, or even perform computations on multiple variables to produce something new. While we'll have to come up with the ideas for our new variables, we can vibe code our way through actually creating them. We're going to create a few new variables, years on the charts, the proportion of words that are profanity, and a binary indicator if the song was a number one hit. Let's do them one at a time. Add a variable called years on the charts to the song's data frame. Great, it's added a new variable called years_on_charts, and what it's done is taken weeks_on_chart and divided it by 52. So let's keep that. We'll go ahead and run it and accept it because it seems like a reasonable thing to do. We'll take a look at it and make…