Page Visits Funnel project

I am working on the Page Visits Funnel project in R. Step 3 says"how long is the visits data frame?" I interpreted this to mean “how many rows”. When I coded that and hit save, nothing happened. So I checked the hint which says: " Use nrows() to find out the number of rows in a data frame." so I coded it this way:

total_visits <- visits %>%
	nrows()

and also this way:
total_visits <- nrows(visits)
Neither solution produces a result upon saving. What is the error, please?

I’ve also tried:

total_visits <- visits_cart %>%
nrows()
head(total_visits)

This didn’t seem to work, either.

It’s nrow() not nrows().

Also I suggest that you put the nrow in the inspection area.

Sorry, I also have a question about this project.
I´m trying to find the answer for step 5.
What percent of users who visited Cool T-Shirts Inc. ended up not placing a t-shirt in their cart?
I hope you can help me.
Thanks!

Here is how I tried to solve step 5 (and prior steps):

{r error=TRUE}
# define visits_cart here:
visits_cart <- visits %>%
  left_join(cart)
visits_cart
# define total_visits here:
total_visits <- nrow(visits)
total_visits
# define visit_no_cart here:
visit_no_cart <- visits_cart %>%
  filter(is.na(cart_time))
visit_no_cart

visit_no_cart_count <- nrow(visit_no_cart)
visit_no_cart_count
# calculate visit_no_cart_percent here:
visit_no_cart_percent <- visit_no_cart_count/total_visits
visit_no_cart_percent

The calculation came out to 82.6%. Is this what you got?

1 Like

Hi

Right now, I’m on step 6, which goes like this:

" Repeat the left join for cart and checkout and count NA values. What percentage of users put items in their cart, but did not proceed to checkout?"

So, before I could find the percentage mentioned, I needed to make a data frame which only had the carts that had not proceeded to checkout. To do this, I wrote the following code:

cart_checkout <- cart %>%
left_join(checkout) %>%
filter(is.na(checkout))

cart_checkout

However, when I do this, I get the following error:

Error: Result must have length 348, not 452

I don’t understand what they mean with this code…

Cheers, Jóhann Örn

it should be

filter(is.na(checkout_time))

you forgot to finish the column name.

Hello there,

I have a question regarding to question number 8.

What percentage of users proceeded to checkout, but did not purchase a t-shirt?

I took a different approach to this question compared to the walkthrough video but I thought it makes sense until I realized the answer I got is different than the answer in the video. I got 0.147058823529, in the video the answer is 0.16889632107. Can anyone look through my code and let me know why did I get a different answer? I looked through the code a couple times and couldn’t figure out which part might have caused a different answer.

I approached the calculation based on the merged table of all four DataFrames but in the video, the solution is to only merge Checkout and Purchase dataframes and proceed with the calculations from there just like question 5 and 6.

Here is my code:

all_data = visits.merge(cart, how = 'left').merge(checkout, how = 'left').merge(purchase, how = 'left')
#Here I am trying to find how many users have reached to the checkout phase. 
checkout = len(all_data[all_data.checkout_time.notnull()])
print(checkout)
#prints 816.
#Then, I find out how many people did not made a purchase but reached to the checkout phase by using logical operator '&' with notnull() and isnull().
purchase_null = len(all_data[all_data.checkout_time.notnull() & all_data.purchase_time.isnull()])
#prints 120.
print(float(purchase_null)/checkout)
#prints 0.147058823529

Code from the video:

checkout_purchase = pd.merge(checkout,purchase, how='left')
checkout_time_rows = len(checkout_purchase)
print(checkout_time_rows)
#prints 598
purchase_null = len(checkout_purchase[checkout_purchase.purchase_time.isnull()])
print(purchase_null)
#prints 101
print(float(purchase_null)/checkout_time_rows)
#prints 0.16889632107

Thank you in advance!

I’m having an error:

Error in eval(lhs, parent, parent): object 'all_data' not found

This is due to this:

all_data <- all_data %>%
  mutate(time_to_purchase = purchase_time - visit_time)

Can you explain to me what I should change?