top of page
Search

Food Marketing Analysis Project (Python)

Feb 19, 2025
2 min read

Updated: Mar 5, 2025

This is my project analyzing real food marketing data using Pandas for Data Analysis.





Step 1: Importing Pandas and Loading the Data We start by importing the Pandas library and loading the dataset from our local computer.

import pandas as pd
food = pd.read_csv(r'C:\Users\Yeyian PC\Downloads\python excel\u_food_marketing.csv')
food.head()
  • pd.read_csv() reads the dataset.

  • food.head() shows the first few rows of the data.


Step 2: Displaying More Data We configure Pandas to display more rows and columns so we can see all the data.

pd.set_option('display.max.rows', 2300)
pd.set_option('display.max.columns', 50)
food

Step 3: Checking and Removing Duplicates

food[food.duplicated()].count() # Checking for duplicates
food.drop_duplicates(keep=False, inplace=True) # Removing duplicates
food.info()  # Checking the dataset structure after removing duplicates
  • duplicated() checks for repeated rows.

  • drop_duplicates(keep=False, inplace=True) removes them.

  • info() shows data details.

Step 4: Adding a New Column - Total Children

food['Total_Children'] = food[['Kidhome','Teenhome']].sum(axis=1)
food.head()
  • This adds up the number of kids and teens into a new column called Total_Children.


Step 5: Encoding Marital Status

food['marital_Divorced'] = food['marital_Divorced'].replace({1:5,0:0})
food['marital_Married'] = food['marital_Married'].replace({1:4,0:0})
food['marital_Single'] = food['marital_Single'].replace({1:3,0:0})
food['marital_Together'] = food['marital_Together'].replace({1:2,0:0})
food['marital_Widow'] = food['marital_Widow'].replace({1:1,0:0})
food['Marital_Status'] = food[['marital_Divorced','marital_Married','marital_Single','marital_Together','marital_Widow']].sum(axis=1)
food['Marital_Status_str'] = food['Marital_Status'].map({5: 'Divorced', 4: 'Married', 3:'Single', 2: 'Together', 1:'Widow'})
  • This converts marital status into numerical and text values for analysis.


Step 6: Encoding Education Levels

food['education_2n Cycle'] = food['education_2n Cycle'].replace({1:1,0:0})
food['education_Basic'] = food['education_Basic'].replace({1:2,0:0})
food['education_Graduation'] = food['education_Graduation'].replace({1:3,0:0})
food['education_Master'] = food['education_Master'].replace({1:4,0:0})
food['education_PhD'] = food['education_PhD'].replace({1:5,0:0})
food['Education_Status']  = food[['education_2n Cycle','education_Basic','education_Graduation','education_Master','education_PhD']].sum(axis=1)
  • This converts education levels into a numerical format.



Step 7: Checking Campaign Acceptance

food['Accepted_Campaigns'] =  food[['AcceptedCmp3','AcceptedCmp4','AcceptedCmp5','AcceptedCmp2','AcceptedCmp1', 'Response']].sum(axis=1)
food['Accepted_Campaigns'] = (food['Accepted_Campaigns'] != 0).astype(int)
  • This counts how many marketing campaigns a person has accepted.



Step 8: Finding Correlations

numeric_food = food.select_dtypes(include=['number'])
all_correlations = numeric_food.corr(method='pearson')
all_correlations = all_correlations[(all_correlations > 0.3) & (all_correlations < 1)]
  • Finds relationships between numerical values in the dataset.


Step 9: Categorizing Age Groups

def assign_age_group(Age):
    age_groups = [(23, 30), (31, 40), (41, 50), (51, 60), (61, 70), (71, 85)]
    for age_range in age_groups:
        if age_range[0] <= Age <= age_range[1]:
            return f"{age_range[0]} - {age_range[1]}"
    return "Unknown"

food['Age_Group'] = food['Age'].apply(assign_age_group)
  • This categorizes ages into groups.


Step 10: Visualizing Data with Seaborn

import seaborn as sns
import matplotlib.pyplot as plt
sns.pointplot(data=food, x='Age_Group', y='Accepted_Campaigns')
plt.show()
  • This graph shows which age groups accept campaigns more.


Step 11: Understanding Spending Habits

grouped_food = food.groupby('Age_Group')['MntTotal'].sum().reset_index()
sns.barplot(x='Age_Group', y='MntTotal', data=grouped_food)
plt.title('Amount Spent Per Age Group')
plt.show()
  • This graph shows how much different age groups spend.


Step 12: Comparing Purchases by Type

sum_food = pd.DataFrame(food[['NumWebPurchases','NumCatalogPurchases','NumStorePurchases']].sum(),columns=['Sums'])
sum_food = sum_food.reset_index()
sum_food.rename(columns={'index':'Type_of_Purchase'}, inplace=True)
sns.barplot(x='Type_of_Purchase', y='Sums', data=sum_food)
plt.show()
  • This visualizes purchase type (web, catalog, store).

Step 13: Understanding Correlations with Purchases

sns.regplot(x='Total_Children', y='MntTotal', data=food)
sns.regplot(x='Education_Status', y='Accepted_Campaigns', data=food)
sns.countplot(x='Marital_Status_str', data=food)
  • These graphs analyze how factors like children and marital status affect spending.

Findings:

  1. Age 30-70 spends more money but accepts fewer campaigns.

  2. Catalog purchases accept more campaigns, but in-store purchases spend more.

  3. People with fewer kids are more likely to accept campaigns.

  4. Education level does not impact purchasing behavior.

  5. Married, single, and together individuals spend more money.


Marketing Recommendations:

  • Target middle-aged, high-income individuals with no kids.

  • Split marketing efforts: 40% catalog, 30% store, 30% web.

  • Focus on 21-30 and 70+ age groups for campaign targeting.

This analysis helps businesses understand who spends more and who is likely to engage with marketing campaigns.





 
 
 

1 Comment


Darri Harber
Darri Harber
Jan 18

Nice work!!!

Like
vvffg_5_edited_edited.png

Data analytics professional with a recent BBA in Business Economics. Proficient in data analysis platforms including MySQL, Google Spreadsheets, Excel, Tableau, Python, R, Pandas, Azure, AWS, Big Query, Econometrics, and data visualization. Adept at extracting actionable insights and presenting data-driven recommendations to stakeholders. Eager to leverage technical skills and academic knowledge to drive impactful business decisions.

•    SQL (MySQL, PostgreSQL, Big Query)   
•    Tableau (Advanced Data Preparation, Creating Dashboards, Data Cleaning)
•    Python (Pandas, NumPy, Matplotlib, Seaborn)    
•    Excel (VLOOKUP, Pivot Tables, Conditional Formatting, Automation)    
•    Microsoft Power BI      
•    Google Spreadsheets
•    Aws
•    Azure           
•    Econometrics
•    Microsoft Office: Proficient in Outlook, Word, Excel, PowerPoint Microsoft Navision
•    Knowledge: Educated in Economic Concepts, Financial Analytical Skills

 

Education:

Bachelor of Business Administration, Business Economics at Georgia State University      

- (3.5 GPA): Data Collection & Analysis, Data Structures & Algorithms, Economic Research

 

Certifications:
•    Analyst Builder for Data Analyst Certification: (Advanced MySQL for Data Analysis, Pandas, Python, Tableau)
•    Google Data Analytics Certification: (Advanced Excel for Automation, R, Big Query) 
•    Market Research Foundations (Market Research Program)

  • GitHub
  • LinkedIn
bottom of page