大数据毕设没思路?用Hadoop+Spark构建基于大数据的当当网图书畅销榜分析与可视化系统

82 阅读12分钟

💖💖作者:IT跃迁谷毕设展 💙💙个人简介:曾长期从事计算机专业培训教学,本人也热爱上课教学,语言擅长Java、微信小程序、Python、Golang、安卓Android等,开发项目包括大数据、深度学习、网站、小程序、安卓、算法。平常会做一些项目定制化开发、代码讲解、答辩教学、文档编写、也懂一些降重方面的技巧。平常喜欢分享一些自己开发中遇到的问题的解决办法,也喜欢交流技术,大家有技术代码这一块的问题可以问我! 💛💛想说的话:感谢大家的关注与支持! 💜💜

Java实战项目集

微信小程序实战项目集

Python实战项目集

安卓Android实战项目集

大数据实战项目集

💕💕文末获取源码

大数据的当当网图书畅销榜分析与可视化系统-选题背景

随着中国图书市场规模持续扩大,据开卷信息发布的《2022年中国图书零售市场报告》显示,全国图书零售市场总规模达977.7亿元,其中网络渠道销售占比超过70%,当当网作为国内领先的图书电商平台,其畅销榜数据蕴含着丰富的市场信息与读者行为模式。图书行业正面临数字化转型挑战,传统出版社与书商缺乏对海量销售数据的深度挖掘能力,难以精准把握市场脉搏。当当网每年发布的畅销榜包含大量图书信息,涵盖排名、评分、评论量、价格等多维度数据,这些数据若能被系统化分析,将为行业决策提供关键参考。而大数据技术的发展为解决这一问题提供了可能,Hadoop与Spark等框架能够高效处理海量非结构化数据,Python与Java语言的数据分析生态也日趋成熟,为构建图书畅销榜分析系统创造了技术条件。

基于大数据的当当网图书畅销榜分析与可视化系统在实际应用层面具有多方面价值。对出版社而言,该系统能够通过年度畅销书类型分布分析和阅读主题演变追踪,揭示读者偏好变化趋势,指导选题方向与内容策划,降低出版风险;通过价格敏感度分析和折扣策略评估,优化图书定价模型,提升市场竞争力。对书店与电商平台来说,系统提供的季节性畅销趋势和作者影响力指数分析,有助于合理安排采购计划和库存管理,提高运营效率。对读者服务方面,系统通过不同年龄段偏好分析和用户互动热度图,能够优化推荐算法,提升用户体验。在学术意义上,本系统将大数据技术与图书市场研究相结合,探索了Hadoop、Spark等框架在垂直行业中的应用模式,为数据驱动的行业研究提供了新思路。系统采用的多维度分析方法也为图书市场研究领域提供了可复制的技术框架与分析范式。

大数据的当当网图书畅销榜分析与可视化系统-系统功能介绍

本系统《基于大数据的当当网图书畅销榜分析与可视化系统》采用Hadoop+Spark大数据框架作为核心技术支撑,结合Python/Java双语言开发方案,实现对当当网图书畅销榜数据的全面分析与可视化展示。系统架构上,后端可选择Django或Spring Boot(Spring+SpringMVC+Mybatis)框架,前端采用Vue+ElementUI+Echarts技术栈,确保数据展示的直观性与交互性。功能模块涵盖四大核心板块:市场趋势分析(包括年度畅销书类型分布、出版时间与上榜关系、畅销书持续力、季节性趋势及关键词热度分析)、读者偏好分析(评分与评论关系、推荐指数影响因素、年龄段偏好、阅读主题演变及用户互动热度图)、价格与营销分析(价格区间与排名关系、折扣策略有效性、电子书与纸质书价格差异、价格敏感度变化及促销效果ROI分析)以及作者与出版社分析(头部作者影响力指数、出版社市场占有率、国内外作者作品比较、出版社专业领域、翻译作品市场表现及作者品牌忠诚度分析)。通过Hadoop的HDFS分布式存储与Spark的内存计算能力,结合Spark SQL、Pandas、NumPy等数据处理工具,系统能高效处理海量图书销售数据,挖掘市场规律,为出版社选品策略、营销决策及读者服务提供数据支持,同时为图书行业市场趋势预测提供科学依据。

大数据的当当网图书畅销榜分析与可视化系统-技术选型

大数据框架:Hadoop+Spark(本次没用Hive,支持定制) 开发语言:Python+Java(两个版本都支持) 后端框架:Django+Spring Boot(Spring+SpringMVC+Mybatis)(两个版本都支持) 前端:Vue+ElementUI+Echarts+HTML+CSS+JavaScript+jQuery 详细技术点:Hadoop、HDFS、Spark、Spark SQL、Pandas、NumPy 数据库:MySQL

大数据的当当网图书畅销榜分析与可视化系统-视频展示

演示视频

大数据的当当网图书畅销榜分析与可视化系统-图片展示

大屏—上 大屏—下 首页 读者偏好分析 价格与营销分析 市场趋势分析 作者与出版社分析 当当图书列表 当当图书详情

大数据的当当网图书畅销榜分析与可视化系统-代码展示

//大数据预处理与大数据分析部分代码展示
def preprocess_bestseller_data(spark, input_path):
    # 读取原始数据
    raw_df = spark.read.csv(input_path, header=True, inferSchema=True)
    # 处理缺失值
    df = raw_df.na.fill("0", ["ebooks_price", "discount"])
    df = df.na.fill("未知", ["author", "publisher"])
    # 价格数据处理与转换
    df = df.withColumn("original_price", regexp_replace(col("original_price"), "[¥]", "").cast(FloatType()))
    df = df.withColumn("discount_price", regexp_replace(col("discount_price"), "[¥]", "").cast(FloatType()))
    df = df.withColumn("ebooks_price", 

                      when(col("ebooks_price").isNull() | (col("ebooks_price") == ""), lit(0.0))

                      .otherwise(regexp_replace(col("ebooks_price"), "[¥]", "").cast(FloatType())))
    # 评分数据标准化
    df = df.withColumn("star", 
                     when(col("star") == "0%", lit(0.0))
                     .otherwise(regexp_replace(col("star"), "%", "").cast(FloatType()) / 100))
    df = df.withColumn("recommend", regexp_replace(col("recommend"), "%", "").cast(FloatType()) / 100)
    # 时间特征提取
    df = df.withColumn("publication_date", to_date(col("publication_date"), "yyyy-MM-dd"))
    df = df.withColumn("publication_year", year(col("publication_date")))
    df = df.withColumn("publication_month", month(col("publication_date")))
    # 计算图书上榜时间与出版时间的间隔
    df = df.withColumn("time_to_bestseller", 
                     when(col("publication_year").isNotNull() & col("ranking_year").isNotNull(),
                          col("ranking_year") - col("publication_year"))
                     .otherwise(null()))
    # 提取图书类别特征
    book_type_mapping = create_book_type_mapping()
    df = df.withColumn("book_category", extract_book_category_udf(col("name"), book_type_mapping))
    # 创建季节特征
    df = df.withColumn("publication_season", 
                     when((col("publication_month") >= 3) & (col("publication_month") <= 5), "春季")
                     .when((col("publication_month") >= 6) & (col("publication_month") <= 8), "夏季")
                     .when((col("publication_month") >= 9) & (col("publication_month") <= 11), "秋季")
                     .otherwise("冬季"))
    # 提取关键词特征
    df = df.withColumn("keywords", extract_keywords_udf(col("name")))
    # 计算价格折扣率
    df = df.withColumn("discount_rate", 
                     when(col("original_price") > 0, 
                          round(col("discount_price") / col("original_price"), 2))
                     .otherwise(1.0))

    return df
# 核心功能1: 年度畅销书类型分布分析
def analyze_yearly_book_type_distribution(spark, cleaned_df):
    # 按年份和图书类型分组统计
    yearly_type_distribution = cleaned_df.groupBy("ranking_year", "book_category").count()
    # 计算每年的总书籍数
    yearly_totals = cleaned_df.groupBy("ranking_year").count().withColumnRenamed("count", "yearly_total")
    # 连接两个DataFrame
    distribution_with_total = yearly_type_distribution.join(yearly_totals, "ranking_year")
    # 计算每种类型在当年的占比
    result = distribution_with_total.withColumn(
        "percentage", 
        round((col("count") * 100.0 / col("yearly_total")), 2)
    )
    # 按年份和占比排序
    result = result.orderBy("ranking_year", col("percentage").desc())
    # 计算同比增长率
    window_spec = Window.partitionBy("book_category").orderBy("ranking_year")
    result = result.withColumn(
        "prev_year_percentage", 
        lag("percentage", 1).over(window_spec)
    )
    result = result.withColumn(
        "yoy_growth", 
        when(col("prev_year_percentage").isNotNull(),
             round(((col("percentage") - col("prev_year_percentage")) / col("prev_year_percentage")) * 100, 2)
            ).otherwise(null())
    )
    # 识别每年增长最快的类型
    yearly_max_growth = result.filter(col("yoy_growth").isNotNull()) \
                             .groupBy("ranking_year") \
                             .agg(max("yoy_growth").alias("max_growth"))
    trending_categories = result.join(
        yearly_max_growth,
        (result["ranking_year"] == yearly_max_growth["ranking_year"]) & 
        (result["yoy_growth"] == yearly_max_growth["max_growth"])
    ).select(result["ranking_year"], result["book_category"], result["yoy_growth"])
    # 计算各类型的长期趋势斜率
    result_pd = result.select("ranking_year", "book_category", "percentage").toPandas()
    trends = {}
    for category in result_pd["book_category"].unique():
        category_data = result_pd[result_pd["book_category"] == category]
        if len(category_data) >= 3:  # 至少需要3年数据计算趋势
            x = category_data["ranking_year"].values
            y = category_data["percentage"].values
            slope, _, _, _, _ = stats.linregress(x, y)
            trends[category] = slope
    return result, trending_categories, trends
# 核心功能2: 畅销书持续力分析
def analyze_bestseller_longevity(spark, cleaned_df):
    # 统计每本书出现在畅销榜的年份数
    book_years = cleaned_df.groupBy("name", "author").agg(
        countDistinct("ranking_year").alias("years_on_list"),
        collect_list("ranking_year").alias("years"),
        collect_list("rank").alias("ranks")
    )
    # 筛选出多年上榜的图书
    multi_year_books = book_years.filter(col("years_on_list") > 1)
    # 计算排名变化率
    def calculate_rank_change(years, ranks):
        if len(years) <= 1 or len(ranks) <= 1:
            return 0.0
        # 按年份排序
        sorted_data = sorted(zip(years, ranks), key=lambda x: x[0])
        sorted_ranks = [r for _, r in sorted_data]
        # 计算平均排名变化
        changes = [sorted_ranks[i] - sorted_ranks[i-1] for i in range(1, len(sorted_ranks))]
        avg_change = sum(changes) / len(changes)
        return float(avg_change)
    calculate_rank_change_udf = udf(calculate_rank_change, FloatType())
    # 应用UDF计算排名变化
    multi_year_books = multi_year_books.withColumn(
        "avg_rank_change", 
        calculate_rank_change_udf(col("years"), col("ranks"))
    )
    # 获取每本书的详细信息
    book_details = cleaned_df.groupBy("name", "author").agg(
        avg("star").alias("avg_star"),
        avg("comment").alias("avg_comment"),
        avg("recommend").alias("avg_recommend"),
        first("publisher").alias("publisher"),
        first("book_category").alias("category")
    )
    # 合并数据
    longevity_analysis = multi_year_books.join(book_details, ["name", "author"])
    # 计算持续力指数 (自定义公式)
    longevity_analysis = longevity_analysis.withColumn(
        "longevity_index",
        round(
            col("years_on_list") * 0.5 +
            (10 - abs(col("avg_rank_change"))) * 0.3 +
            col("avg_star") * 100 * 0.2,
            2
        )
    )
    # 按持续力指数排序
    result = longevity_analysis.orderBy(col("longevity_index").desc())
    return result
# 核心功能3: 读者偏好分析 - 评分与评论关系研究
def analyze_rating_comment_relationship(spark, cleaned_df):
    # 创建评分区间
    df = cleaned_df.withColumn(
        "star_range",
        when(col("star") < 0.2, "0-0.2")
        .when((col("star") >= 0.2) & (col("star") < 0.4), "0.2-0.4")
        .when((col("star") >= 0.4) & (col("star") < 0.6), "0.4-0.6")
        .when((col("star") >= 0.6) & (col("star") < 0.8), "0.6-0.8")
        .otherwise("0.8-1.0")
    )
    # 按评分区间分组计算平均评论数
    star_comment_relation = df.groupBy("star_range").agg(
        count("*").alias("book_count"),
        round(avg("comment"), 2).alias("avg_comment_count"),
        round(stddev("comment"), 2).alias("comment_stddev"),
        round(avg("recommend"), 4).alias("avg_recommend")
    )
    # 计算皮尔逊相关系数
    correlation = df.stat.corr("star", "comment")
    # 按评分区间和图书类型分组
    category_correlation = df.groupBy("book_category").agg(
        round(corr("star", "comment"), 4).alias("star_comment_correlation"),
        round(avg("star"), 4).alias("avg_star"),
        round(avg("comment"), 2).alias("avg_comment")
    )
    # 计算高评分但低评论量的异常书籍
    anomaly_books = df.withColumn(
        "is_anomaly",
        when((col("star") > 0.8) & (col("comment") < 100), 1).otherwise(0)
    )
    anomaly_count = anomaly_books.filter(col("is_anomaly") == 1).count()
    total_high_rating = anomaly_books.filter(col("star") > 0.8).count()
    anomaly_percentage = 0
    if total_high_rating > 0:
        anomaly_percentage = (anomaly_count / total_high_rating) * 100
    # 计算评论量与推荐率的关系
    comment_recommend_relation = df.withColumn(
        "comment_range",
        when(col("comment") < 100, "0-100")
        .when((col("comment") >= 100) & (col("comment") < 500), "100-500")
        .when((col("comment") >= 500) & (col("comment") < 1000), "500-1000")
        .when((col("comment") >= 1000) & (col("comment") < 5000), "1000-5000")
        .otherwise("5000+")
    ).groupBy("comment_range").agg(
        count("*").alias("book_count"),
        round(avg("recommend"), 4).alias("avg_recommend"),
        round(avg("star"), 4).alias("avg_star")
    )
    # 返回分析结果
    return {
        "star_comment_relation": star_comment_relation,
        "overall_correlation": correlation,
        "category_correlation": category_correlation,
        "anomaly_percentage": anomaly_percentage,
        "comment_recommend_relation": comment_recommend_relation
    }
# 核心功能4: 价格与营销分析 - 折扣策略有效性分析
def analyze_discount_strategy_effectiveness(spark, cleaned_df):
    # 创建折扣区间
    df = cleaned_df.withColumn(
        "discount_range",
        when(col("discount_rate") < 0.5, "超低折扣(<50%)")
        .when((col("discount_rate") >= 0.5) & (col("discount_rate") < 0.7), "大折扣(50%-70%)")
        .when((col("discount_rate") >= 0.7) & (col("discount_rate") < 0.9), "中折扣(70%-90%)")
        .otherwise("小折扣(>=90%)")

    )
    # 按折扣区间分析排名、评论和推荐情况
    discount_analysis = df.groupBy("discount_range").agg(
        count("*").alias("book_count"),
        round(avg("rank"), 2).alias("avg_rank"),
        round(avg("comment"), 2).alias("avg_comment"),
        round(avg("recommend"), 4).alias("avg_recommend"),
        round(avg("star"), 4).alias("avg_star")
    )
    # 计算折扣力度与排名的相关性
    rank_correlation = df.stat.corr("discount_rate", "rank")
    # 计算折扣力度与评论量的相关性
    comment_correlation = df.stat.corr("discount_rate", "comment")
    # 按图书类型分析最佳折扣策略
    category_discount = df.groupBy("book_category", "discount_range").agg(
        count("*").alias("book_count"),
        round(avg("rank"), 2).alias("avg_rank")
    )
    # 找出每个类别中排名最好的折扣区间
    window_spec = Window.partitionBy("book_category").orderBy("avg_rank")
    category_best_discount = category_discount.withColumn("rank_in_category", row_number().over(window_spec))
    category_best_discount = category_best_discount.filter(col("rank_in_category") == 1)
    # 计算ROI (Return on Investment) - 以评论量增长作为回报指标
    df = df.withColumn(
        "discount_amount", 
        col("original_price") - col("discount_price")
    )
    df = df.withColumn(
        "roi_index",
        when(col("discount_amount") > 0, col("comment") / col("discount_amount"))
        .otherwise(0)
    )
    # 按折扣区间计算平均ROI
    roi_analysis = df.groupBy("discount_range").agg(
        round(avg("roi_index"), 2).alias("avg_roi"),
        round(avg("discount_amount"), 2).alias("avg_discount_amount"),
        round(avg("comment"), 2).alias("avg_comment")
    )
    # 返回分析结果
    return {
        "discount_analysis": discount_analysis,
        "rank_correlation": rank_correlation,
        "comment_correlation": comment_correlation,
        "category_best_discount": category_best_discount,
        "roi_analysis": roi_analysis
    }
# 核心功能5: 作者与出版社分析 - 出版社市场占有率分析
def analyze_publisher_market_share(spark, cleaned_df):
    # 计算每个出版社的图书数量
    publisher_counts = cleaned_df.groupBy("publisher").count()
    # 计算总图书数
    total_books = cleaned_df.count()
    # 计算市场占有率
    market_share = publisher_counts.withColumn(
        "market_share_percent", 
        round((col("count") * 100.0 / total_books), 2)
    )
    # 按年份分析市场占有率变化
    yearly_publisher = cleaned_df.groupBy("ranking_year", "publisher").count()
    # 计算每年的总书籍数
    yearly_totals = cleaned_df.groupBy("ranking_year").count().withColumnRenamed("count", "yearly_total")
    # 连接数据
    yearly_market_share = yearly_publisher.join(yearly_totals, "ranking_year")
    # 计算每年的市场占有率
    yearly_market_share = yearly_market_share.withColumn(
        "yearly_market_share", 
        round((col("count") * 100.0 / col("yearly_total")), 2)
    )
    # 计算主要出版社的市场占有率变化趋势
    window_spec = Window.partitionBy("publisher").orderBy("ranking_year")
    yearly_market_share = yearly_market_share.withColumn(
        "prev_year_share", 
        lag("yearly_market_share", 1).over(window_spec)
    )
    yearly_market_share = yearly_market_share.withColumn(
        "yoy_change", 
        when(col("prev_year_share").isNotNull(),
             round(col("yearly_market_share") - col("prev_year_share"), 2)
            ).otherwise(0)
    )
    # 计算出版社的平均排名和评分
    publisher_performance = cleaned_df.groupBy("publisher").agg(
        round(avg("rank"), 2).alias("avg_rank"),
        round(avg("star"), 4).alias("avg_star"),
        round(avg("comment"), 2).alias("avg_comment")
    )
    # 合并市场占有率和性能指标
    result = market_share.join(publisher_performance, "publisher")
    # 计算综合实力指数
    result = result.withColumn(
        "strength_index",
        round(
            col("market_share_percent") * 0.4 +
            (500 - col("avg_rank")) / 5 * 0.3 +
            col("avg_star") * 100 * 0.2 +
            log(col("avg_comment") + 1) * 0.1,
            2
        )
    )
    # 按综合实力排序
    result = result.orderBy(col("strength_index").desc())
    # 筛选主要出版社(市场份额>1%)
    major_publishers = result.filter(col("market_share_percent") > 1)
    return result, yearly_market_share, major_publishers

大数据的当当网图书畅销榜分析与可视化系统-结语

💕💕

Java实战项目集

微信小程序实战项目集

Python实战项目集

安卓Android实战项目集

大数据实战项目集

💟💟如果大家有任何疑虑,欢迎在下方位置详细交流。