Food Marketing Analysis Project (Python)
Updated: Mar 5, 2025
This is my project analyzing real food marketing data using Pandas for Data Analysis.
Link To Code: https://github.com/mkitchens5/Merrill-Portfolio/blob/main/Food%20Marketing%20Data%20A%20(2).ipynb
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 duplicatesduplicated() 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:
Age 30-70 spends more money but accepts fewer campaigns.
Catalog purchases accept more campaigns, but in-store purchases spend more.
People with fewer kids are more likely to accept campaigns.
Education level does not impact purchasing behavior.
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.
Link To the FULL Code: https://github.com/mkitchens5/Merrill-Portfolio/blob/main/Food%20Marketing%20Data%20A%20(2).ipynb




Nice work!!!