IT评测·应用市场-qidao123.com技术社区

标题: 大数据平台Hadoop综合应用实训 [打印本页]

作者: tsx81428    时间: 2025-4-17 16:05
标题: 大数据平台Hadoop综合应用实训
一、实训目标
认识数据库的构建、ketle数据洗濯,把握Python编程技术实现网络爬虫收罗数据、统计分析与可视化。
二、实训内容
(一)模仿点评网站的摆设
(二)网络数据爬取和数据的洗濯
(三)数据统计分析和可视化
三、实训设备要求
一个win10体系,一个ubuntu体系
四、实训操纵步骤
(一)模仿点评网站摆设
1.安装python3.6
  1. sudo apt-get install python3.6
复制代码

2.安装apach
  1. sudo apt-get install apache2
复制代码

3.安装Django1.9

4.设置apache2

vim /etc/apache2/sites-available/000-default.conf
5.安装和设置mysql
sudo  cat /etc/mysql/debian.cnf

vim /home/joker/spider/spider/settings.py

6.安装restframework
pip3 install djangorestramework==3.4.4

7.安装pymysql
sudo apt install python-pip

8.启动apache2

/spider$ python3 manage.py runserver 192.168.182.141:8001




(二)网络数据爬取和数据的洗濯
1.新建数据库
  1. import pymysql
  2. # 此类操作数据库
  3. class DBConnect():
  4. #这个类用于连接数据库、插入数据、查询数据
  5.     def __init__(self):
  6.         self.host = '192.168.182.141'
  7.         self.port = 3306
  8.         self.user = 'root'
  9.         self.passwd = '123456'
  10.         self.db = 'testdazhong'
  11.     # 连接到具体的数据库
  12.     def connectDatabase(self):
  13.         conn = pymysql.connect(host=self.host,
  14.                                port=self.port,
  15.                                user=self.user,
  16.                                passwd=self.passwd,
  17.                                db=self.db,
  18.                                charset='utf8')
  19.         return conn
  20.     # 插入数据
  21.     def insert(self, sql, *params):
  22.         conn = self.connectDatabase()
  23.         cur = conn.cursor()
  24.         cur.execute(sql, params)
  25.         conn.commit()
  26.         cur.close()
  27.         conn.close()
  28.     # 查询数据
  29.     def select(self, sql):
  30.         conn = self.connectDatabase()
  31.         cur = conn.cursor()
  32.         try:
  33.             # 执行SQL语句
  34.             cur.execute(sql)
  35.             conn.commit()
  36.             # 获取所有记录列表
  37.             results = cur.fetchall()
  38.             return results
  39.         except:
  40.             print("Error: unable to fetch data")
  41.         cur.close()
  42.         conn.close()
复制代码
3. kettle数据洗濯

(三)统计分析与可视化

  1. from pyecharts import Line, Bar, Page, WordCloud
  2. from spider import dbconnect
  3. #查询商铺名称、计算综合评价分数=(口味+环境+服务)/3的函数
  4. def evaluateshop(city):
  5.     #连接数据库
  6.     dbcon = dbconnect.DBConnect()
  7.     dbcon.connectDatabase();
  8.     #定义查询语句,查询商铺名称、计算综合评价分数
  9.     nsql = '''SELECT shopName,(tasteScore+environmentScore+serviceScore)/3.0 as avg from dazhongoutput WHERE city="%s" ORDER BY (tasteScore+environmentScore+serviceScore)/3.0 DESC;'''%(city)
  10.     LData =dbcon.select(nsql)
  11.     LShopName = []
  12.     LAvg = []
  13.     #返回商铺名称、综合评价分数
  14.     for idata in LData:
  15.         LShopName.append(idata[0])
  16.         LAvg.append(round(idata[1], 2))
  17.     return [LShopName,LAvg]
  18. #TOP20商铺综合分数画图函数
  19. def plottop20(score_y1, score_y2, score_y3):
  20.     #定义页面
  21.     page = Page()
  22.     #折线图定义、添加数据和配置项
  23.     line1 = Line("济南饭店评分统计", "数据来源于点评网TOP100", width=1200)
  24.     line1.add("综合", score_y1[0][:20], score_y1[1][:20], is_label_show=True, is_more_utils=True)
  25.     line2 = Line("青岛饭店评分统计", "数据来源于点评网TOP100", width=1200)
  26.     line2.add("综合", score_y2[0][:20], score_y2[1][:20], is_label_show=True, is_more_utils=True)
  27.     line3 = Line("威海饭店评分统计", "数据来源于点评网TOP100", width=1200)
  28.     line3.add("综合", score_y3[0][:20], score_y3[1][:20], is_label_show=True, is_more_utils=True)
  29.    #页面添加图形
  30.     page.add(line1)
  31.     page.add(line2)
  32.     page.add(line3)
  33.     #生成HTML,数据可视化展示
  34.     page.render("山东3大城市TOP20商铺综合服务评分.html")
  35. if __name__ == '__main__':
  36.     #评估3大城市商铺综合分数
  37.     shop1 = evaluateshop("济南")
  38.     shop2 = evaluateshop("青岛")
  39.     shop3 = evaluateshop("威海")
  40.     #建立数据列表画图,生成HTML
  41.     score_x = []
  42.     score_y1, score_y2, score_y3 = [], [], []
  43.     for data, data2, data3 in zip(shop1, shop2, shop3):
  44.         score_y1.append(data)
  45.         score_y2.append(data2)
  46.         score_y3.append(data3)
  47.     plottop20(score_y1, score_y2, score_y3)
复制代码

 


  1. from pyecharts import Pie, Page,Bar
  2. from spider import dbconnect
  3. #查询统计某城市菜品分类名
  4. def foodClass(city):
  5.     #连接数据库
  6.     dbcon = dbconnect.DBConnect()
  7.     dbcon.connectDatabase();
  8.     fsql = '''SELECT COUNT(mainCategoryName),mainCategoryName from dazhongoutput  where city="%s" GROUP BY mainCategoryName;'''%(city)
  9.     #查询获得菜品分类商店梳理、菜品分类名称数据返回
  10.     LData = dbcon.select(fsql)
  11.     return LData
  12. #菜品分类画图函数
  13. def plotfoodclass():
  14.     #查询统计济南的菜品分类以及数量
  15.     Laddress = []
  16.     Lsum = []
  17.     [Lsum.append(i[0]) for i in foodClass("济南")]
  18.     [Laddress.append(i[1]) for i in foodClass("济南")]
  19.     print(Laddress)
  20.     print(Lsum)
  21.     #定义页面
  22.     page = Page()
  23.     #添加饼图的数据和配置项
  24.     fpie1 = Pie("济南菜品分类", title_pos='center')
  25.     fpie1.add("", Laddress, Lsum, radius=[30, 75], label_text_color=None,
  26.             is_label_show=True, legend_orient='vertical',
  27.             legend_pos='auto', is_legend_show=False)
  28.     #添加柱状图的数据和配置项
  29.     fbar1 = Bar("济南菜品分类", "数据来源于点评网TOP100",title_pos ='center')
  30.     fbar1.add("济南", Laddress, Lsum, mark_point=["max", "min"],legend_pos="right")
  31.     # 查询统计青岛的菜品分类以及数量
  32.     Laddress = []
  33.     Lsum = []
  34.     [Lsum.append(i[0]) for i in foodClass("青岛")]
  35.     [Laddress.append(i[1]) for i in foodClass("青岛")]
  36.     print(Laddress)
  37.     print(Lsum)
  38.     # 添加饼图的数据和配置项
  39.     fpie2 = Pie("青岛菜品分类", title_pos='center')
  40.     fpie2.add("", Laddress, Lsum, radius=[30, 75], label_text_color=None,
  41.             is_label_show=True, legend_orient='vertical',
  42.             legend_pos='auto', is_legend_show=False)
  43.     # 添加柱状图的数据和配置项
  44.     fbar2 = Bar("青岛菜品分类", "数据来源于点评网TOP100", title_pos='center')
  45.     fbar2.add("青岛", Laddress, Lsum, mark_point=["max", "min"], legend_pos="right")
  46.     # 查询统计威海的菜品分类以及数量
  47.     Laddress = []
  48.     Lsum = []
  49.     [Lsum.append(i[0]) for i in foodClass("威海")]
  50.     [Laddress.append(i[1]) for i in foodClass("威海")]
  51.     print(Laddress)
  52.     print(Lsum)
  53.     # 添加饼图的数据和配置项
  54.     fpie3 = Pie("威海菜品分类", title_pos='center')
  55.     fpie3.add("", Laddress, Lsum, radius=[30, 75], label_text_color=None,
  56.             is_label_show=True, legend_orient='vertical',
  57.             legend_pos='auto', is_legend_show=False)
  58.     # 添加柱状图的数据和配置项
  59.     fbar3 = Bar("威海菜品分类", "数据来源于点评网TOP100", title_pos='center')
  60.     fbar3.add("威海", Laddress, Lsum, mark_point=["max", "min"], legend_pos="right")
  61.    #页面上添加图形
  62.     page.add(fpie1)
  63.     page.add(fbar1)
  64.     page.add(fpie2)
  65.     page.add(fbar2)
  66.     page.add(fpie3)
  67.     page.add(fbar3)
  68.     page.render("山东3大城市菜品分类.html")
  69. if __name__ == '__main__':
  70.     plotfoodclass()
复制代码

 

  1. from pyecharts import Pie, Page,Bar
  2. from spider import dbconnect
  3. #查询统计某城市菜品分类名
  4. def foodClass(city):
  5.     #连接数据库
  6.     dbcon = dbconnect.DBConnect()
  7.     dbcon.connectDatabase();
  8.     fsql = '''SELECT COUNT(mainCategoryName),mainCategoryName from dazhongoutput  where city="%s" GROUP BY mainCategoryName;'''%(city)
  9.     #查询获得菜品分类商店梳理、菜品分类名称数据返回
  10.     LData = dbcon.select(fsql)
  11.     return LData
  12. #菜品分类画图函数
  13. def plotfoodclass():
  14.     #查询统计济南的菜品分类以及数量
  15.     Laddress = []
  16.     Lsum = []
  17.     [Lsum.append(i[0]) for i in foodClass("济南")]
  18.     [Laddress.append(i[1]) for i in foodClass("济南")]
  19.     print(Laddress)
  20.     print(Lsum)
  21.     #定义页面
  22.     page = Page()
  23.     #添加饼图的数据和配置项
  24.     fpie1 = Pie("济南菜品分类", title_pos='center')
  25.     fpie1.add("", Laddress, Lsum, radius=[30, 75], label_text_color=None,
  26.             is_label_show=True, legend_orient='vertical',
  27.             legend_pos='auto', is_legend_show=False)
  28.     #添加柱状图的数据和配置项
  29.     fbar1 = Bar("济南菜品分类", "数据来源于点评网TOP100",title_pos ='center')
  30.     fbar1.add("济南", Laddress, Lsum, mark_point=["max", "min"],legend_pos="right")
  31.     # 查询统计青岛的菜品分类以及数量
  32.     Laddress = []
  33.     Lsum = []
  34.     [Lsum.append(i[0]) for i in foodClass("青岛")]
  35.     [Laddress.append(i[1]) for i in foodClass("青岛")]
  36.     print(Laddress)
  37.     print(Lsum)
  38.     # 添加饼图的数据和配置项
  39.     fpie2 = Pie("青岛菜品分类", title_pos='center')
  40.     fpie2.add("", Laddress, Lsum, radius=[30, 75], label_text_color=None,
  41.             is_label_show=True, legend_orient='vertical',
  42.             legend_pos='auto', is_legend_show=False)
  43.     # 添加柱状图的数据和配置项
  44.     fbar2 = Bar("青岛菜品分类", "数据来源于点评网TOP100", title_pos='center')
  45.     fbar2.add("青岛", Laddress, Lsum, mark_point=["max", "min"], legend_pos="right")
  46.     # 查询统计威海的菜品分类以及数量
  47.     Laddress = []
  48.     Lsum = []
  49.     [Lsum.append(i[0]) for i in foodClass("威海")]
  50.     [Laddress.append(i[1]) for i in foodClass("威海")]
  51.     print(Laddress)
  52.     print(Lsum)
  53.     # 添加饼图的数据和配置项
  54.     fpie3 = Pie("威海菜品分类", title_pos='center')
  55.     fpie3.add("", Laddress, Lsum, radius=[30, 75], label_text_color=None,
  56.             is_label_show=True, legend_orient='vertical',
  57.             legend_pos='auto', is_legend_show=False)
  58.     # 添加柱状图的数据和配置项
  59.     fbar3 = Bar("威海菜品分类", "数据来源于点评网TOP100", title_pos='center')
  60.     fbar3.add("威海", Laddress, Lsum, mark_point=["max", "min"], legend_pos="right")
  61.    #页面上添加图形
  62.     page.add(fpie1)
  63.     page.add(fbar1)
  64.     page.add(fpie2)
  65.     page.add(fbar2)
  66.     page.add(fpie3)
  67.     page.add(fbar3)
  68.     page.render("山东3大城市菜品分类.html")
  69. if __name__ == '__main__':
  70.     plotfoodclass()
复制代码
五、总结及心得体会
在举行大数据爬取可视化分析的实训过程中,我深刻体会到了数据在当今社会的重要性和价值。通过对大数据的爬取、洗濯、分析和可视化,我们能够从海量的数据中发掘出有价值的信息,为决定提供支持,推动企业发展,甚至改变社会。首先,在实训过程中,我学会了怎样使用Python等编程语言来举行数据爬取。通过编写爬虫程序,我能够自动化地从网页上抓取数据,实现大规模数据的获取。这让我深刻体会到了数据爬取的便捷和高效,同时也认识到了数据爬取中大概遇到的反爬步伐和解决方法。其次,数据洗濯是数据分析的重要一环。在实训中,我学会了怎样对爬取得到的数据举行洗濯和预处置惩罚,包括去除重复值、处置惩罚缺失值、统一数据格式等操纵。只有经过洗濯的数据才能够被准确地分析和可视化,否则会影响终极的结果和结论。接着,数据分析是实训的焦点环节。通过对洗濯后的数据举行统计分析、机器学习等方法,我们可以发现数据之间的关联、规律和趋势,从而得出有价值的结论。数据分析需要联合范畴知识和数据发掘技术,通过创建模子和算法来解决实际标题,这也是我在实训中不停探索和学习的方向。末了,数据可视化是将数据分析结果以图形化的方式展示出来,让人们更直观地明白数据背后的含义。在实训中,我学会了怎样使用可视化工具如Matplotlib、Seaborn、Tableau等来出现数据,包括制作折线图、柱状图、热力图等,以及怎样选择符合的图表类型来展示差别类型的数据。总的来说,通过这次大数据爬取可视化分析的实训,我不但学会了数据处置惩罚和分析的根本技能,还深刻认识到了数据对于决媾和创新的重要性。在未来的学习和工作中,我将继续深耕数据范畴,不停提升本身的数据分析能力,为实现数据驱动的智能决定贡献本身的力量。

免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。




欢迎光临 IT评测·应用市场-qidao123.com技术社区 (https://dis.qidao123.com/) Powered by Discuz! X3.4