Changes in consumer habits in community pharmacies in Portugal during the SARS-CoV-2 pandemic using Market Basket Analysis and Network Diagrams

  • Rúben Duarte Pereira Infosaúde-CEFAR, Associação Nacional de Farmácias
  • David Lopes
  • Zilda Mendes
Keywords: Association Rules, Community Pharmacies, SARS-CoV-2, Market Basket Analysis, Network Diagrams, Portugal



The sales of over-the-counter (OTC) products in community pharmacies in Portugal is analogous to standard retail business. Several techniques such as cross-selling have been used to increase sales in this segment by encouraging customers to purchase complementary products or services. This technique analyzes transactional data using different methodologies, such as market basket analysis (MBA), which explores associations between items within transactions to uncover customer buying habits and trends. The pairings are supported by measures of interestingness such as the exclusivity of associations of items, lift [1].

OTC products are divided in hierarchical categories, such as beauty, hygiene, and body care, all which include sublevels (e.g. skin, face and hair). Previous works explored the use of network diagrams to group categories based on interpretation of the association rules as links between items [2].

This work explores the association of product categories through generation of rules using MBA in yearly transactional data prior to and during the SARS-CoV-2 pandemic period (2019 and 2020-2021, respectively) to uncover changes in basket purchasing behavior.


Data comprising transactions from 1st January 2019 through 31st December 2021 were collected from 2519 community pharmacies in Portugal (approximately 86,2% of all community pharmacies countrywide) and divided in three yearly subsets. Each set was analyzed using the MBA apriori algorithm [3] to extract association rules composed of one antecedent and one consequent product category. Lift measures of the resulting rules were compared across the 3 years to conclude about changes in basket associations. Results were filtered considering absolute variation in lift higher than 10 from 2019 to 2020, and lower than 10 from 2020 to 2021. Moreover, minimum support of 300 occurrences in any of the subsets was imposed. Changes in OTC groups were interpreted by visualizing the networks of product categories produced by the association rules calculated for each subset (year).


The total number of transactions analyzed from 2019, 2020 and 2021 were 65.232.346, 58.374.315 and 63.858.049, respectively, and a total of 54 associations were considered for analysis. Among these, three use cases stand out: (i) the occurrence of iron supplements and products containing vitamin D in the same transaction was observed in only 19 transactions in 2019. In 2020 and 2021 the support was 613 and 784, respectively, and lift increased from 1.46 to 19.55 and 20.42 in the same years. Figure 1 shows strong association of iron supplements with breastfeed products in 2019. The lack of solar exposition can explain the purchase increase of products containing vitamin D during the pandemic lockdowns (Figure 2); (ii) contrarily, the lift of the association of appetite suppressants and female anti-cellulite products reduced from 63.09 (2019) to 9.51 (2020) and 4.90 (2021). Also, a significant decreased was observed in the number of transactions with the association from pre to the pandemic period, from 353 (2019) to 35 (2020) and 24 (2021). The seasonality of weight loss purchases coupled with the decrease in social and summer activities in 2020 and 2021 decreased the strengths of associations of these products overall (Figures 3 and 4); (iii) the sales of surgical masks, previously highly coupled with various disposable material (e.g. gloves, tissues and bags) stand out as a mixture of effects of both previous use cases. Though the lift reduced from 15.98 (2019) to 3.17 (2020) and 5.37 (2021), the support increased from 740 (2019) to 5053 (2020) and 2293 (2021). Surgical masks were very likely to be bought with almost any product in community pharmacies during the pandemic, which decreased the exclusivity of this association.


The recommendations generated by analytical approaches from retail unravel a panoply of possibilities from evidence-based medicine to monetary profit. Despite the progressive adoption as a contributor to business of community pharmacies, the approach proposed allows recommendation of medication for managing treatment secondary effects and decrease discomfort, which ultimately promotes quality of life.

How to Cite
Pereira, R. D., Lopes, D., & Mendes, Z. (2022). Changes in consumer habits in community pharmacies in Portugal during the SARS-CoV-2 pandemic using Market Basket Analysis and Network Diagrams. Journal of Statistics on Health Decision, 4(1), 91-92.