import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
# Load the data
df = pd.read_csv('itscope_analysis_data.csv')
# 1. Current Position Analysis
def analyze_current_position(df):
# Group by product to find ranks
product_ranks = df.groupby(['manufacturerSKU']).apply(
lambda x: x.sort_values('competitor_price').reset_index(drop=True)
)
# Find EET's current position
eet_positions = []
for name, group in product_ranks.groupby(level=0):
eet_row = group[group['is_eet'] == 1]
if not eet_row.empty:
eet_positions.append({
'manufacturerSKU': name,
'current_rank': eet_row.index[0] + 1,
'eet_price': eet_row['competitor_price'].values[0],
'eet_stock': eet_row['competitor_stock'].values[0],
'eet_cost': eet_row['eet_cost_price'].values[0],
'current_margin': (eet_row['competitor_price'].values[0] - eet_row['eet_cost_price'].values[0]) / eet_row['competitor_price'].values[0] * 100
})
eet_position_df = pd.DataFrame(eet_positions)
return eet_position_df
# 2. Rank #1 Scenario Analysis
def analyze_rank1_scenario(df, eet_position_df):
# For each product, what would it take to be rank #1?
rank1_scenarios = []
for name, group in df.groupby('manufacturerSKU'):
# Skip if EET is not in this product group
if name not in eet_position_df['manufacturerSKU'].values:
continue
# Sort by price to find rank #1
sorted_group = group.sort_values('competitor_price')
rank1_price = sorted_group.iloc[0]['competitor_price']
# Get EET's data for this product
eet_data = eet_position_df[eet_position_df['manufacturerSKU'] == name].iloc[0]
# Calculate required margin to be rank #1
required_margin = (rank1_price - eet_data['eet_cost']) / rank1_price * 100
# Stock comparison
competitors = group[group['is_eet'] == 0]
avg_competitor_stock = competitors['competitor_stock'].mean()
stock_ratio = eet_data['eet_stock'] / avg_competitor_stock if avg_competitor_stock > 0 else float('inf')
rank1_scenarios.append({
'manufacturerSKU': name,
'current_rank': eet_data['current_rank'],
'current_price': eet_data['eet_price'],
'current_margin': eet_data['current_margin'],
'rank1_price': rank1_price,
'required_margin': required_margin,
'margin_difference': required_margin - eet_data['current_margin'],
'eet_cost': eet_data['eet_cost'],
'eet_stock': eet_data['eet_stock'],
'avg_competitor_stock': avg_competitor_stock,
'stock_ratio': stock_ratio,
'margin_category': categorize_margin(required_margin)
})
rank1_df = pd.DataFrame(rank1_scenarios)
return rank1_df
def categorize_margin(margin):
if margin < 0:
return "Negative Margin"
elif margin < 4:
return "Low Margin (0-4%)"
else:
return "Profitable (>4%)"
# 3. Stock-Weighted Decision Logic
def apply_stock_weighted_logic(rank1_df, stock_ratio_threshold=3.0):
# Apply stock-based pricing logic
rank1_df['price_recommendation'] = rank1_df.apply(
lambda row: determine_price_strategy(row, stock_ratio_threshold),
axis=1
)
return rank1_df
def determine_price_strategy(row, stock_ratio_threshold):
if row['stock_ratio'] > stock_ratio_threshold:
# EET has significantly more stock
if row['current_margin'] > 4:
return "Maintain current price (stock advantage)"
else:
return "Consider slight price increase (stock advantage)"
else:
# Competitive stock levels
if row['required_margin'] < 0:
return "Cost issue - cannot compete on price"
elif row['required_margin'] < 4:
return "Match rank #1 price with caution (low margin)"
else:
return "Match rank #1 price (profitable)"
# 4. Generate Summary Statistics
def generate_summary_stats(rank1_df):
summary = {
'total_products': len(rank1_df),
'current_rank1_count': len(rank1_df[rank1_df['current_rank'] == 1]),
'current_rank1_percentage': len(rank1_df[rank1_df['current_rank'] == 1]) / len(rank1_df) * 100,
'avg_margin_for_rank1': rank1_df['required_margin'].mean(),
'median_margin_for_rank1': rank1_df['required_margin'].median(),
'negative_margin_count': len(rank1_df[rank1_df['required_margin'] < 0]),
'negative_margin_percentage': len(rank1_df[rank1_df['required_margin'] < 0]) / len(rank1_df) * 100,
'low_margin_count': len(rank1_df[(rank1_df['required_margin'] >= 0) & (rank1_df['required_margin'] < 4)]),
'low_margin_percentage': len(rank1_df[(rank1_df['required_margin'] >= 0) & (rank1_df['required_margin'] < 4)]) / len(rank1_df) * 100,
'profitable_margin_count': len(rank1_df[rank1_df['required_margin'] >= 4]),
'profitable_margin_percentage': len(rank1_df[rank1_df['required_margin'] >= 4]) / len(rank1_df) * 100,
}
return summary
# Main execution
def main():
# Load and process data
df = pd.read_csv('itscope_analysis_data.csv')
# Run analyses
eet_position_df = analyze_current_position(df)
rank1_df = analyze_rank1_scenario(df, eet_position_df)
final_df = apply_stock_weighted_logic(rank1_df)
summary = generate_summary_stats(final_df)
# Output results
print("EET Deutschland IT Scope Competitive Analysis")
print("=============================================")
print(f"Total products analyzed: {summary['total_products']}")
print(f"Currently rank #1: {summary['current_rank1_count']} ({summary['current_rank1_percentage']:.2f}%)")
print(f"Average margin needed for rank #1: {summary['avg_margin_for_rank1']:.2f}%")
print(f"Median margin needed for rank #1: {summary['median_margin_for_rank1']:.2f}%")
print("\nMargin Distribution for Rank #1 Strategy:")
print(f"Negative margin: {summary['negative_margin_count']} ({summary['negative_margin_percentage']:.2f}%)")
print(f"Low margin (0-4%): {summary['low_margin_count']} ({summary['low_margin_percentage']:.2f}%)")
print(f"Profitable margin (>4%): {summary['profitable_margin_count']} ({summary['profitable_margin_percentage']:.2f}%)")
# Save detailed results
final_df.to_csv('eet_pricing_recommendations.csv', index=False)
# Create visualizations
create_visualizations(final_df, summary)
def create_visualizations(df, summary):
# Margin distribution
plt.figure(figsize=(10, 6))
sns.histplot(df['required_margin'], bins=20)
plt.axvline(x=0, color='r', linestyle='--')
plt.axvline(x=4, color='g', linestyle='--')
plt.title('Distribution of Required Margins for Rank #1')
plt.xlabel('Margin (%)')
plt.ylabel('Count')
plt.savefig('margin_distribution.png')
# Current vs required rank #1 prices
plt.figure(figsize=(10, 6))
plt.scatter(df['current_price'], df['rank1_price'])
plt.plot([df['current_price'].min(), df['current_price'].max()],
[df['current_price'].min(), df['current_price'].max()], 'r--')
plt.title('Current EET Price vs. Rank #1 Price')
plt.xlabel('Current EET Price')
plt.ylabel('Rank #1 Price')
plt.savefig('price_comparison.png')
# Margin category distribution
plt.figure(figsize=(10, 6))
category_counts = df['margin_category'].value_counts()
plt.pie(category_counts, labels=category_counts.index, autopct='%1.1f%%')
plt.title('Margin Categories for Rank #1 Strategy')
plt.savefig('margin_categories.png')
if __name__ == "__main__":
main()