Exploratory Community

How to Filter Only Ones that has Data in All Groups like Years?

#1

Sometimes when you have countries (or customers) that don’t make purchases from your store for all the years. That’s not a bad thing, just part of the business. :wink:

As you can see the above, some countries have 4 bars, which means they have made at least some kind of purchases in all the 4 years of 2012, 2013, 2014, 2015.

However, you can also see that some countries don’t have any data in some years.

Now if we want to show only the countries with 4 years of data (or bars), what can we do?

We can take the following 4 steps of the data wrangling to get the job done.

  1. Extract Year information from Date column.
  2. Group By the data frame by Country column.
  3. Create a calculation with Mutate step to count the number of years.
  4. Filter the data.

I’ve written a note to demonstrate step by step of how to do this.

-Kan