目录
一、案例背景
直播电商作为电子商务与直播行业深度融合的新兴商业模式,近年来呈现出爆发式增长态势。它借助主播的影响力和实时互动性,打破了传统电商的静态展示模式,极大地提升了消费者的购物体验和参与感。从美妆、服饰到数码产品、食品生鲜,直播电商几乎覆盖了所有商品品类。然而,行业发展并非一帆风顺,面临着产品质量参差不齐、主播带货能力差异大、消费者信任度有待提高以及市场竞争激烈等诸多挑战。通过运用 Python 对直播电商行业相关数据进行全面深入的分析,能够助力商家精准选品、优化营销策略,帮助平台加强监管、提升服务质量,为行业的健康可持续发展提供有力支持。
二、代码实现
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
import requests
from bs4 import BeautifulSoup
2.1 数据收集
数据来源广泛,涵盖行业研究报告网站(如艾媒咨询、艾瑞咨询)、直播电商平台(如淘宝直播、抖音电商)公开数据、社交媒体上关于直播电商的讨论以及电商平台的商品销售数据。
- 从艾媒咨询网站抓取直播电商市场规模数据:
url = 'https://www.iimedia.cn/research/live_ecommerce.html'
headers = {
'User - Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36'
}
response = requests.get(url, headers = headers)
soup = BeautifulSoup(response.text, 'html.parser')
market_size_data = []
table = soup.find('table', class_='market - size - table')
rows = table.find_all('tr')
for row in rows[1:]:
cols = row.find_all('td')
year = cols[0].text.strip()
market_size = float(cols[1].text.strip().replace('亿元', ''))
market_size_data.append({'Year': year, 'Market_Size': market_size})
market_size_df = pd.DataFrame(market_size_data)
- 从某直播电商平台获取热门主播的带货数据(假设通过 API 获取,且已获得授权):
import json
api_url = 'https://api.livecommerceplatform.com/top_anchor_sales'
headers = {
'Authorization': 'your_api_key',
'Content - Type': 'application/json'
}
response = requests.get(api_url, headers = headers)
if response.status_code == 200:
anchor_sales_data = json.loads(response.text)
anchor_sales_df = pd.DataFrame(anchor_sales_data)
else:
print('Failed to get anchor sales data')
2.2 数据探索性分析
# 查看市场规模数据基本信息
print(market_size_df.info())
# 查看热门主播带货数据基本信息
print(anchor_sales_df.info())
# 分析直播电商市场规模随时间变化趋势
market_size_df['Year'] = pd.to_numeric(market_size_df['Year'])
plt.figure(figsize=(12, 6))
sns.lineplot(x='Year', y='Market_Size', data=market_size_df)
plt.title('Trend of Live E - commerce Market Size')
plt.xlabel('Year')
plt.ylabel('Market Size (billion yuan)')
plt.show()
# 查看热门主播的销售额分布
plt.figure(figsize=(10, 6))
sns.histplot(anchor_sales_df['Sales_Amount'], kde=True)
plt.title('Distribution of Sales Amount of Top Anchors')
plt.xlabel('Sales Amount (ten thousand yuan)')
plt.ylabel('Frequency')
plt.show()
2.3 数据清洗
# 市场规模数据清洗
# 检查并处理缺失值
market_size_df.dropna(inplace = True)
# 去除重复记录
market_size_df = market_size_df.drop_duplicates()
# 热门主播带货数据清洗
# 处理异常销售额数据,如销售额为负数
anchor_sales_df = anchor_sales_df[anchor_sales_df['Sales_Amount'] > 0]
# 处理缺失值,对于关键信息缺失的记录可考虑删除
anchor_sales_df = anchor_sales_df.dropna(subset=['Anchor_Name', 'Sales_Amount'])