From the course: Python for Marketing (2019)

Unlock this course with a free trial

Join today to access over 22,600 courses taught by industry experts.

Creating new datasets with Groupby

Creating new datasets with Groupby - Python Tutorial

From the course: Python for Marketing (2019)

Creating new datasets with Groupby

- Now we get to apply the group by function. First, we're going to create a variable called average time, and inside average time we are going to store the group by function so we can use it later on. First, we're going to pass the data frame that we will be grouping by. So that is ga_page_data, and we want to group by the index which is essentially the page names. And after we have grouped by page names, we want to look up the column Average Time on Page and calculate the mean, or that column. In this case, we need to pass an argument numeric_only equals false, and that's because we're dealing with daytime and not numbers. Now I want to take the average time variable, and I want to store it into a data frame. We are going to call it ga_time, then we're going to equals pd, calling pandas again, then DataFrame, and once we pass avg_time, we close it and we run it. We have no errors. That's good. Next, we are going to…

Contents