【Python爬虫+可视化案例】采集电商网站商品数据信息,并可视化分析

爬虫+可视化案例 :苏宁易购

  1. 案例所需要掌握的知识点:
  • selenium的使用
  • html标签数据解析方法
  1. 需要准备的环境:
  • python 3.8
  • pycharm 2022专业版
  • selenium python里面的第三方库 可以用来操作浏览器

爬虫代码展示

所需模块
【代码领取 请看文末名片】

import time
from selenium import webdriver  # 第三方库 操作浏览器驱动的 浏览器驱动用来操作浏览器的
from selenium.webdriver.common.by import By
import csv

新建文件

f = open('苏宁易购.csv', mode='a', encoding='utf-8', newline='')
csv_writer = csv.writer(f)
csv_writer.writerow(['title', 'price', 'comment', 'store_stock', 'href'])
  1. 打开浏览器 是没问题的
driver = webdriver.Chrome()
  1. 打开网站
driver.get("https://****/iPhone14/")
for i in range(15):
  1. 将滚动条 拉到最下方
    # 通过js代码去操作 页面
    # deocument.documentElement.scrollHeight: 获取当前整个页面的高度
    # document.documentElement.scrollTop: 当前滚动条的位置
    # document.documentElement.scrollTop = document.documentElement.scrollHeight: 将当前滚动条的位置设置为 整个页面的高度
    for page in range(0, 14500, 2900):
        driver.execute_script('document.documentElement.scrollTop = ' + str(page))
        time.sleep(1)
  1. 取数据

.product-box: 匹配到所有的商品标签

    goods = driver.find_elements(By.CSS_SELECTOR, ".product-box")
    ""代码获取:文末名片""
    for good in goods:
        price = good.find_element(By.CSS_SELECTOR, ".price-box").text
        title = good.find_element(By.CSS_SELECTOR, ".title-selling-point").text
        href = good.find_element(By.CSS_SELECTOR, ".title-selling-point a").get_attribute("href")
        comment = good.find_element(By.CSS_SELECTOR, ".evaluate-old.clearfix").text
        store_stock = good.find_element(By.CSS_SELECTOR, ".store-stock").text
        print(title, price, comment, store_stock)
        csv_writer.writerow([title, price, comment, store_stock, href])
    driver.find_element(By.CSS_SELECTOR, "#nextPage").click()
# 阻塞 不让程序结束 因为程序结束 浏览器就自动关闭了
# 退出浏览器
driver.quit()

在这里插入图片描述

可视化效果演示

一共就是以下三个表格,外加一个词云图

我觉得如果是大学生把这个交给老师,应该也许大概可能,老师会觉得你还不错吧,哈哈哈

在这里插入图片描述

开个玩笑,不过现在大学生基本都写完作业,早早的放假了

还是希望这篇文章可以帮助到大家吧,emm不过最近没怎么更新,已经没什么人看文章了哈哈

请添加图片描述
请添加图片描述
请添加图片描述
请添加图片描述

可视化代码

{源码领取,请看文末名片
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "d19250a4",
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd \n",
    "import jieba\n",
    "import time\n",
    "from pyecharts.charts import Bar,Line,Map,Page,Pie  \n",
    "from pyecharts import options as opts \n",
    "from pyecharts.globals import SymbolType"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "69c29f78",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>title</th>\n",
       "      <th>price</th>\n",
       "      <th>comment</th>\n",
       "      <th>store_stock</th>\n",
       "      <th>href</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>Apple iPhone 14 128G 午夜色 移动联通电信5G手机</td>\n",
       "      <td>¥5999.00</td>\n",
       "      <td>1.3万+评价</td>\n",
       "      <td>苏宁自营</td>\n",
       "      <td>https://product.suning.com/0000000000/12391268...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>Apple iPhone 14 Pro Max 256G 暗紫色 移动联通电信5G手机</td>\n",
       "      <td>¥9899.00</td>\n",
       "      <td>6300+评价</td>\n",
       "      <td>苏宁自营</td>\n",
       "      <td>https://product.suning.com/0000000000/12391268...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>Apple iPhone 14 Pro Max 128G 暗紫色 移动联通电信5G手机</td>\n",
       "      <td>¥8999.00</td>\n",
       "      <td>6300+评价</td>\n",
       "      <td>苏宁自营</td>\n",
       "      <td>https://product.suning.com/0000000000/12391268...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>Apple iPhone 14 Pro 256G 深空黑色 移动联通电信5G手机</td>\n",
       "      <td>¥8899.00</td>\n",
       "      <td>6400+评价</td>\n",
       "      <td>苏宁自营</td>\n",
       "      <td>https://product.suning.com/0000000000/12391268...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>Apple iPhone 14 Pro 128G 暗紫色 移动联通电信5G手机</td>\n",
       "      <td>¥7999.00</td>\n",
       "      <td>6400+评价</td>\n",
       "      <td>苏宁自营</td>\n",
       "      <td>https://product.suning.com/0000000000/12391268...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1693</th>\n",
       "      <td>圣幻 iphone11手机壳苹果11pro硅胶套iphone11PROMAX全包防摔ipho...</td>\n",
       "      <td>¥46.00</td>\n",
       "      <td>200+评价</td>\n",
       "      <td>任意门数码专营店</td>\n",
       "      <td>https://product.suning.com/0070067325/11398343...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1694</th>\n",
       "      <td>圣幻 iphone11苹果11proMax手机壳薄透明苹果11全包边11Pro电镀软壳防摔1...</td>\n",
       "      <td>¥46.00</td>\n",
       "      <td>300+评价</td>\n",
       "      <td>任意门数码专营店</td>\n",
       "      <td>https://product.suning.com/0070067325/11398610...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1695</th>\n",
       "      <td>圣幻 iphone11/12/12pro手机壳透明防摔苹果12ProMAX保护套新款轻薄硅胶...</td>\n",
       "      <td>¥46.00</td>\n",
       "      <td>1800+评价</td>\n",
       "      <td>任意门数码专营店</td>\n",
       "      <td>https://product.suning.com/0070067325/12179125...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1696</th>\n",
       "      <td>VMONN苹果13手机壳新款防摔iphone13Pro max翻盖保护皮套mini钱包插卡</td>\n",
       "      <td>¥48.00</td>\n",
       "      <td>0评价</td>\n",
       "      <td>骑猪漫舞数码配件专营店</td>\n",
       "      <td>https://product.suning.com/0070154072/12321840...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1697</th>\n",
       "      <td>KIVee 可逸 PD20W快充套苹果PD充电器+1米数据线适用于苹果iPhone14/13pro</td>\n",
       "      <td>¥58.00</td>\n",
       "      <td>200+评价</td>\n",
       "      <td>苏宁自营</td>\n",
       "      <td>https://product.suning.com/0000000000/12395644...</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>1698 rows × 5 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                                                  title     price  comment  \\\n",
       "0                   Apple iPhone 14 128G 午夜色 移动联通电信5G手机  ¥5999.00  1.3万+评价   \n",
       "1           Apple iPhone 14 Pro Max 256G 暗紫色 移动联通电信5G手机  ¥9899.00  6300+评价   \n",
       "2           Apple iPhone 14 Pro Max 128G 暗紫色 移动联通电信5G手机  ¥8999.00  6300+评价   \n",
       "3              Apple iPhone 14 Pro 256G 深空黑色 移动联通电信5G手机  ¥8899.00  6400+评价   \n",
       "4               Apple iPhone 14 Pro 128G 暗紫色 移动联通电信5G手机  ¥7999.00  6400+评价   \n",
       "...                                                 ...       ...      ...   \n",
       "1693  圣幻 iphone11手机壳苹果11pro硅胶套iphone11PROMAX全包防摔ipho...    ¥46.00   200+评价   \n",
       "1694  圣幻 iphone11苹果11proMax手机壳薄透明苹果11全包边11Pro电镀软壳防摔1...    ¥46.00   300+评价   \n",
       "1695  圣幻 iphone11/12/12pro手机壳透明防摔苹果12ProMAX保护套新款轻薄硅胶...    ¥46.00  1800+评价   \n",
       "1696      VMONN苹果13手机壳新款防摔iphone13Pro max翻盖保护皮套mini钱包插卡    ¥48.00      0评价   \n",
       "1697  KIVee 可逸 PD20W快充套苹果PD充电器+1米数据线适用于苹果iPhone14/13pro    ¥58.00   200+评价   \n",
       "\n",
       "      store_stock                                               href  \n",
       "0            苏宁自营  https://product.suning.com/0000000000/12391268...  \n",
       "1            苏宁自营  https://product.suning.com/0000000000/12391268...  \n",
       "2            苏宁自营  https://product.suning.com/0000000000/12391268...  \n",
       "3            苏宁自营  https://product.suning.com/0000000000/12391268...  \n",
       "4            苏宁自营  https://product.suning.com/0000000000/12391268...  \n",
       "...           ...                                                ...  \n",
       "1693     任意门数码专营店  https://product.suning.com/0070067325/11398343...  \n",
       "1694     任意门数码专营店  https://product.suning.com/0070067325/11398610...  \n",
       "1695     任意门数码专营店  https://product.suning.com/0070067325/12179125...  \n",
       "1696  骑猪漫舞数码配件专营店  https://product.suning.com/0070154072/12321840...  \n",
       "1697         苏宁自营  https://product.suning.com/0000000000/12395644...  \n",
       "\n",
       "[1698 rows x 5 columns]"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_tb = pd.read_csv('苏宁易购.csv')\n",
    "df_tb"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "199ddb66",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'pandas.core.frame.DataFrame'>\n",
      "RangeIndex: 1698 entries, 0 to 1697\n",
      "Data columns (total 5 columns):\n",
      " #   Column       Non-Null Count  Dtype \n",
      "---  ------       --------------  ----- \n",
      " 0   title        1698 non-null   object\n",
      " 1   price        1698 non-null   object\n",
      " 2   comment      1692 non-null   object\n",
      " 3   store_stock  1698 non-null   object\n",
      " 4   href         1698 non-null   object\n",
      "dtypes: object(5)\n",
      "memory usage: 66.5+ KB\n"
     ]
    }
   ],
   "source": [
    "df_tb.info()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "359af5ec",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "<ipython-input-8-e2aeb333fba4>:3: FutureWarning: The default value of regex will change from True to False in a future version.\n",
      "  df_tb['price'] = df_tb['price'].str.replace('\\n26.90', '')\n",
      "<ipython-input-8-e2aeb333fba4>:4: FutureWarning: The default value of regex will change from True to False in a future version. In addition, single character regular expressions will*not* be treated as literal strings when regex=True.\n",
      "  df_tb['comment'] = df_tb['comment'].str.replace('+', '')\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>title</th>\n",
       "      <th>price</th>\n",
       "      <th>comment</th>\n",
       "      <th>store_stock</th>\n",
       "      <th>href</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>Apple iPhone 14 128G 午夜色 移动联通电信5G手机</td>\n",
       "      <td>5999.0</td>\n",
       "      <td>1.3</td>\n",
       "      <td>苏宁自营</td>\n",
       "      <td>https://product.suning.com/0000000000/12391268...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>Apple iPhone 14 Pro Max 256G 暗紫色 移动联通电信5G手机</td>\n",
       "      <td>9899.0</td>\n",
       "      <td>6300.0</td>\n",
       "      <td>苏宁自营</td>\n",
       "      <td>https://product.suning.com/0000000000/12391268...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>Apple iPhone 14 Pro Max 128G 暗紫色 移动联通电信5G手机</td>\n",
       "      <td>8999.0</td>\n",
       "      <td>6300.0</td>\n",
       "      <td>苏宁自营</td>\n",
       "      <td>https://product.suning.com/0000000000/12391268...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>Apple iPhone 14 Pro 256G 深空黑色 移动联通电信5G手机</td>\n",
       "      <td>8899.0</td>\n",
       "      <td>6400.0</td>\n",
       "      <td>苏宁自营</td>\n",
       "      <td>https://product.suning.com/0000000000/12391268...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>Apple iPhone 14 Pro 128G 暗紫色 移动联通电信5G手机</td>\n",
       "      <td>7999.0</td>\n",
       "      <td>6400.0</td>\n",
       "      <td>苏宁自营</td>\n",
       "      <td>https://product.suning.com/0000000000/12391268...</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                         title   price  comment store_stock  \\\n",
       "0          Apple iPhone 14 128G 午夜色 移动联通电信5G手机  5999.0      1.3        苏宁自营   \n",
       "1  Apple iPhone 14 Pro Max 256G 暗紫色 移动联通电信5G手机  9899.0   6300.0        苏宁自营   \n",
       "2  Apple iPhone 14 Pro Max 128G 暗紫色 移动联通电信5G手机  8999.0   6300.0        苏宁自营   \n",
       "3     Apple iPhone 14 Pro 256G 深空黑色 移动联通电信5G手机  8899.0   6400.0        苏宁自营   \n",
       "4      Apple iPhone 14 Pro 128G 暗紫色 移动联通电信5G手机  7999.0   6400.0        苏宁自营   \n",
       "\n",
       "                                                href  \n",
       "0  https://product.suning.com/0000000000/12391268...  \n",
       "1  https://product.suning.com/0000000000/12391268...  \n",
       "2  https://product.suning.com/0000000000/12391268...  \n",
       "3  https://product.suning.com/0000000000/12391268...  \n",
       "4  https://product.suning.com/0000000000/12391268...  "
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_tb['price'] = df_tb['price'].str.replace('¥', '')\n",
    "df_tb['price'] = df_tb['price'].str.replace('到手价', '')\n",
    "df_tb['price'] = df_tb['price'].str.replace('\\n26.90', '')\n",
    "df_tb['comment'] = df_tb['comment'].str.replace('+', '')\n",
    "df_tb['comment'] = df_tb['comment'].str.replace('评价', '')\n",
    "df_tb['comment'] = df_tb['comment'].str.replace('万', '')\n",
    "\n",
    "df_tb['price'] = df_tb['price'].astype('float64')\n",
    "df_tb['comment'] = df_tb['comment'].astype('float64')\n",
    "df_tb.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "e3225a22",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "store_stock\n",
       "Apple产品啟韬专卖店             103802.0\n",
       "任意门数码专营店                   5582.0\n",
       "小米智能生活旗舰店                     1.0\n",
       "小米智能电器旗舰店                     0.0\n",
       "数格尚品数码配件专营店                2417.0\n",
       "深得二手电脑专营店                     0.0\n",
       "直营                            0.0\n",
       "禧运二手靓品专营店                    10.0\n",
       "科华专营店                        84.8\n",
       "竟纬科技专营店                     370.0\n",
       "绿联官方旗舰店                   20620.0\n",
       "绿联数码旗舰店                    8604.8\n",
       "苏宁二手优品授权旗舰店                   0.0\n",
       "苏宁国际\\n3C数码海外专营店             320.0\n",
       "苏宁国际\\n八达通海外专营店             1950.0\n",
       "苏宁国际\\n嘉怡海外专营店             47219.0\n",
       "苏宁国际\\n德天诺海外专营店            17626.0\n",
       "苏宁国际\\n方都数码海外旗舰店           33902.0\n",
       "苏宁国际\\n百思卖海外专营店              225.0\n",
       "苏宁国际\\n黑海数码海外官方旗舰店         11802.0\n",
       "苏宁服务\\nApple智能数码苏宁专卖店    1081901.0\n",
       "苏宁服务\\n小米智能苏宁专卖店               0.0\n",
       "苏宁服务\\n易购优选数码苏宁旗舰店             0.0\n",
       "苏宁服务\\n波格朗苏宁旗舰店               21.0\n",
       "苏宁自营                     161359.6\n",
       "苏宁自营\\n华均魅苏宁旗舰店              416.0\n",
       "讯天国际手机专营店                   480.0\n",
       "诗薇蒂数码专营店                     27.0\n",
       "质点旗舰店                    124720.0\n",
       "迈动智能数码专营店                   300.0\n",
       "锦际数码专营店                    2858.9\n",
       "顺宇数码专营店                    1202.0\n",
       "骑猪漫舞数码配件专营店                   7.0\n",
       "Name: comment, dtype: float64"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_tb.groupby('store_stock')['comment'].sum()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "583489b0",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "store_stock\n",
       "苏宁服务\\nApple智能数码苏宁专卖店    1081901.0\n",
       "苏宁自营                     161359.6\n",
       "质点旗舰店                    124720.0\n",
       "Apple产品啟韬专卖店             103802.0\n",
       "苏宁国际\\n嘉怡海外专营店             47219.0\n",
       "苏宁国际\\n方都数码海外旗舰店           33902.0\n",
       "绿联官方旗舰店                   20620.0\n",
       "苏宁国际\\n德天诺海外专营店            17626.0\n",
       "苏宁国际\\n黑海数码海外官方旗舰店         11802.0\n",
       "绿联数码旗舰店                    8604.8\n",
       "Name: comment, dtype: float64"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "shop_top10 = df_tb.groupby('store_stock')['comment'].sum().sort_values(ascending=False).head(10)\n",
    "shop_top10"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "ad50c7b9",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'C:\\\\02-讲师文件夹\\\\巳月公开课\\\\课题\\\\苏宁易购\\\\1.html'"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#条形图  \n",
    "#bar1 = Bar(init_opts=opts.InitOpts(width='1350px', height='750px')) \n",
    "bar1 = Bar() \n",
    "bar1.add_xaxis(shop_top10.index.tolist())\n",
    "bar1.add_yaxis('', shop_top10.values.tolist()) \n",
    "bar1.set_global_opts(title_opts=opts.TitleOpts(title='iphone13排名Top10苏宁店铺'),\n",
    "                     xaxis_opts=opts.AxisOpts(axislabel_opts=opts.LabelOpts(rotate=-15)),\n",
    "                     visualmap_opts=opts.VisualMapOpts(max_=28669)\n",
    "                    ) \n",
    "\n",
    "bar1.render('1.html')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "657a7e89",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1000元以上      858\n",
       "0~50元        317\n",
       "50~100元       92\n",
       "100~200元      84\n",
       "200~300元       8\n",
       "300~500元       6\n",
       "500~1000元      2\n",
       "Name: price, dtype: int64"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cut_bins = [0,50,100,200,300,500,1000,8888]  \n",
    "cut_labels = ['0~50元', '50~100元', '100~200元', '200~300元', '300~500元', '500~1000元', '1000元以上']\n",
    "\n",
    "price_cut = pd.cut(df_tb['price'],bins=cut_bins,labels=cut_labels)\n",
    "price_num = price_cut.value_counts()\n",
    "price_num"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "569f1dc3",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'C:\\\\02-讲师文件夹\\\\巳月公开课\\\\课题\\\\苏宁易购\\\\2.html'"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "bar3 = Bar() \n",
    "bar3.add_xaxis(['0~50元', '50~100元', '100~200元', '200~300元', '300~500元', '500~1000元', '1000元以上'])\n",
    "bar3.add_yaxis('', [895, 486, 701, 288, 370, 411, 260]) \n",
    "bar3.set_global_opts(title_opts=opts.TitleOpts(title='不同价格区间的商品数量'),\n",
    "                     visualmap_opts=opts.VisualMapOpts(max_=900)) \n",
    "bar3.render('2.html')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "4bfcfcb1",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "price_cut\n",
       "0~50元          80778.9\n",
       "50~100元        27471.5\n",
       "100~200元        6371.9\n",
       "200~300元         320.0\n",
       "300~500元         203.0\n",
       "500~1000元       1600.0\n",
       "1000元以上      1118024.2\n",
       "Name: comment, dtype: float64"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_tb['price_cut'] = price_cut \n",
    "\n",
    "cut_purchase = df_tb.groupby('price_cut')['comment'].sum()\n",
    "cut_purchase"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "61b3f3b9",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "<script>\n",
       "    require.config({\n",
       "        paths: {\n",
       "            'echarts':'https://assets.pyecharts.org/assets/v5/echarts.min'\n",
       "        }\n",
       "    });\n",
       "</script>\n",
       "\n",
       "        <div id=\"2c59c934b8d84dffbde3cc9ff80a5318\" style=\"width:900px; height:500px;\"></div>\n",
       "\n",
       "<script>\n",
       "        require(['echarts'], function(echarts) {\n",
       "                var chart_2c59c934b8d84dffbde3cc9ff80a5318 = echarts.init(\n",
       "                    document.getElementById('2c59c934b8d84dffbde3cc9ff80a5318'), 'white', {renderer: 'canvas'});\n",
       "                var option_2c59c934b8d84dffbde3cc9ff80a5318 = {\n",
       "    \"animationEasing\": \"cubicOut\",\n",
       "    \"animationDelay\": 0,\n",
       "    \"animationDurationUpdate\": 300,\n",
       "    \"animationEasingUpdate\": \"cubicOut\",\n",
       "    \"animationDelayUpdate\": 0,\n",
       "    \"aria\": {\n",
       "        \"enabled\": false\n",
       "    },\n",
       "    \"color\": [\n",
       "        \"#EF9050\",\n",
       "        \"#3B7BA9\",\n",
       "        \"#6FB27C\",\n",
       "        \"#FFAF34\",\n",
       "        \"#D8BFD8\",\n",
       "        \"#00BFFF\",\n",
       "        \"#7FFFAA\"\n",
       "    ],\n",
       "    \"series\": [\n",
       "        {\n",
       "            \"type\": \"pie\",\n",
       "            \"colorBy\": \"data\",\n",
       "            \"legendHoverLink\": true,\n",
       "            \"selectedMode\": false,\n",
       "            \"selectedOffset\": 10,\n",
       "            \"clockwise\": true,\n",
       "            \"startAngle\": 90,\n",
       "            \"minAngle\": 0,\n",
       "            \"minShowLabelAngle\": 0,\n",
       "            \"avoidLabelOverlap\": true,\n",
       "            \"stillShowZeroSum\": true,\n",
       "            \"percentPrecision\": 2,\n",
       "            \"showEmptyCircle\": true,\n",
       "            \"emptyCircleStyle\": {\n",
       "                \"color\": \"lightgray\",\n",
       "                \"borderColor\": \"#000\",\n",
       "                \"borderWidth\": 0,\n",
       "                \"borderType\": \"solid\",\n",
       "                \"borderDashOffset\": 0,\n",
       "                \"borderCap\": \"butt\",\n",
       "                \"borderJoin\": \"bevel\",\n",
       "                \"borderMiterLimit\": 10,\n",
       "                \"opacity\": 1\n",
       "            },\n",
       "            \"data\": [\n",
       "                {\n",
       "                    \"name\": \"0~50\\u5143\",\n",
       "                    \"value\": 80778.90000000004\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"50~100\\u5143\",\n",
       "                    \"value\": 27471.5\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"100~200\\u5143\",\n",
       "                    \"value\": 6371.9\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"200~300\\u5143\",\n",
       "                    \"value\": 320.0\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"300~500\\u5143\",\n",
       "                    \"value\": 203.0\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"500~1000\\u5143\",\n",
       "                    \"value\": 1600.0\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"1000\\u5143\\u4ee5\\u4e0a\",\n",
       "                    \"value\": 1118024.1999999993\n",
       "                }\n",
       "            ],\n",
       "            \"radius\": [\n",
       "                \"35%\",\n",
       "                \"60%\"\n",
       "            ],\n",
       "            \"center\": [\n",
       "                \"50%\",\n",
       "                \"50%\"\n",
       "            ],\n",
       "            \"label\": {\n",
       "                \"show\": true,\n",
       "                \"margin\": 8,\n",
       "                \"formatter\": \"{b}:{d}%\"\n",
       "            },\n",
       "            \"labelLine\": {\n",
       "                \"show\": true,\n",
       "                \"showAbove\": false,\n",
       "                \"length\": 15,\n",
       "                \"length2\": 15,\n",
       "                \"smooth\": false,\n",
       "                \"minTurnAngle\": 90,\n",
       "                \"maxSurfaceAngle\": 90\n",
       "            },\n",
       "            \"rippleEffect\": {\n",
       "                \"show\": true,\n",
       "                \"brushType\": \"stroke\",\n",
       "                \"scale\": 2.5,\n",
       "                \"period\": 4\n",
       "            }\n",
       "        }\n",
       "    ],\n",
       "    \"legend\": [\n",
       "        {\n",
       "            \"data\": [\n",
       "                \"0~50\\u5143\",\n",
       "                \"50~100\\u5143\",\n",
       "                \"100~200\\u5143\",\n",
       "                \"200~300\\u5143\",\n",
       "                \"300~500\\u5143\",\n",
       "                \"500~1000\\u5143\",\n",
       "                \"1000\\u5143\\u4ee5\\u4e0a\"\n",
       "            ],\n",
       "            \"selected\": {},\n",
       "            \"show\": true,\n",
       "            \"left\": \"2%\",\n",
       "            \"top\": \"15%\",\n",
       "            \"orient\": \"vertical\",\n",
       "            \"padding\": 5,\n",
       "            \"itemGap\": 10,\n",
       "            \"itemWidth\": 25,\n",
       "            \"itemHeight\": 14,\n",
       "            \"backgroundColor\": \"transparent\",\n",
       "            \"borderColor\": \"#ccc\",\n",
       "            \"borderWidth\": 1,\n",
       "            \"borderRadius\": 0,\n",
       "            \"pageButtonItemGap\": 5,\n",
       "            \"pageButtonPosition\": \"end\",\n",
       "            \"pageFormatter\": \"{current}/{total}\",\n",
       "            \"pageIconColor\": \"#2f4554\",\n",
       "            \"pageIconInactiveColor\": \"#aaa\",\n",
       "            \"pageIconSize\": 15,\n",
       "            \"animationDurationUpdate\": 800,\n",
       "            \"selector\": false,\n",
       "            \"selectorPosition\": \"auto\",\n",
       "            \"selectorItemGap\": 7,\n",
       "            \"selectorButtonGap\": 10\n",
       "        }\n",
       "    ],\n",
       "    \"tooltip\": {\n",
       "        \"show\": true,\n",
       "        \"trigger\": \"item\",\n",
       "        \"triggerOn\": \"mousemove|click\",\n",
       "        \"axisPointer\": {\n",
       "            \"type\": \"line\"\n",
       "        },\n",
       "        \"showContent\": true,\n",
       "        \"alwaysShowContent\": false,\n",
       "        \"showDelay\": 0,\n",
       "        \"hideDelay\": 100,\n",
       "        \"enterable\": false,\n",
       "        \"confine\": false,\n",
       "        \"appendToBody\": false,\n",
       "        \"transitionDuration\": 0.4,\n",
       "        \"textStyle\": {\n",
       "            \"fontSize\": 14\n",
       "        },\n",
       "        \"borderWidth\": 0,\n",
       "        \"padding\": 5,\n",
       "        \"order\": \"seriesAsc\"\n",
       "    },\n",
       "    \"title\": [\n",
       "        {\n",
       "            \"show\": true,\n",
       "            \"text\": \"\\u4e0d\\u540c\\u4ef7\\u683c\\u533a\\u95f4\\u7684\\u9500\\u552e\\u989d\\u6574\\u4f53\\u8868\\u73b0\",\n",
       "            \"target\": \"blank\",\n",
       "            \"subtarget\": \"blank\",\n",
       "            \"padding\": 5,\n",
       "            \"itemGap\": 10,\n",
       "            \"textAlign\": \"auto\",\n",
       "            \"textVerticalAlign\": \"auto\",\n",
       "            \"triggerEvent\": false\n",
       "        }\n",
       "    ]\n",
       "};\n",
       "                chart_2c59c934b8d84dffbde3cc9ff80a5318.setOption(option_2c59c934b8d84dffbde3cc9ff80a5318);\n",
       "        });\n",
       "    </script>\n"
      ],
      "text/plain": [
       "<pyecharts.render.display.HTML at 0x28981696340>"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data_pair = [list(z) for z in zip(cut_purchase.index.tolist(), cut_purchase.values.tolist())]\n",
    "# 绘制饼图\n",
    "pie1 = Pie() \n",
    "pie1.add('', data_pair, radius=['35%', '60%'])\n",
    "pie1.set_global_opts(title_opts=opts.TitleOpts(title='不同价格区间的销售额整体表现'), \n",
    "                     legend_opts=opts.LegendOpts(orient='vertical', pos_top='15%', pos_left='2%'))\n",
    "pie1.set_series_opts(label_opts=opts.LabelOpts(formatter=\"{b}:{d}%\"))\n",
    "pie1.set_colors(['#EF9050', '#3B7BA9', '#6FB27C', '#FFAF34', '#D8BFD8', '#00BFFF', '#7FFFAA'])\n",
    "pie1.render_notebook() "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "11f85a85",
   "metadata": {},
   "outputs": [],
   "source": [
    "def get_cut_words(content_series):\n",
    "    # 读入停用词表\n",
    "    stop_words = [] \n",
    "    \n",
    "    # with open(r\"E:\\py练习\\数据分析\\stop_words.txt\", 'r', encoding='utf-8') as f:\n",
    "    #     lines = f.readlines()\n",
    "    #     for line in lines:\n",
    "    #         stop_words.append(line.strip())\n",
    "\n",
    "    # 添加关键词\n",
    "    my_words = ['丝袜', '夏天', '女薄款', '一体'] \n",
    "    for i in my_words:\n",
    "        jieba.add_word(i) \n",
    "\n",
    "    # 自定义停用词\n",
    "#     my_stop_words = []\n",
    "#     stop_words.extend(my_stop_words)               \n",
    "\n",
    "    # 分词\n",
    "    word_num = jieba.lcut(content_series.str.cat(sep='。'), cut_all=False)\n",
    "\n",
    "    # 条件筛选\n",
    "    word_num_selected = [i for i in word_num if i not in stop_words and len(i)>=2]\n",
    "    \n",
    "    return word_num_selected"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "9985bd7a",
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Building prefix dict from the default dictionary ...\n",
      "Loading model from cache C:\\Users\\ADMINI~1\\AppData\\Local\\Temp\\jieba.cache\n",
      "Loading model cost 0.580 seconds.\n",
      "Prefix dict has been built successfully.\n"
     ]
    }
   ],
   "source": [
    "text = get_cut_words(content_series=df_tb['title'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "1db0b1ef-12b8-4190-bad7-f939b6068ce3",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}

最后

今天的案例分享到这里就结束啦

下篇文章再见吧

请添加图片描述

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:/a/39910.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

开发工具篇第二十六讲:使用IDEA进行本地调试和远程调试

开发工具篇第二十六讲&#xff1a;使用IDEA进行本地调试和远程调试 Debug用来追踪代码的运行流程&#xff0c;通常在程序运行过程中出现异常&#xff0c;启用Debug模式可以分析定位异常发生的位置&#xff0c;以及在运行过程中参数的变化&#xff1b;并且在实际的排错过程中&am…

C++-string类的模拟实现

本博客基于C官方文档当中给出的string类当中的主要功能实现&#xff0c;来作为参照&#xff0c;简单模拟实现 My-string 。 对于C当中的string类的介绍&#xff0c;在之前的几篇博客当中有说明&#xff0c;如有问题&#xff0c;请参照一下两个博客文章进行参考&#xff1a; (2…

使用 Pytest 运行 yaml 文件来驱动 Appium 自动化测试

目录 前言&#xff1a; 获取 yaml 文件 YamlTest 测试类 Appium 初始化 Pytest 测试类 自定义 runtest demo&#xff1a; 自定义错误输出 Yaml 使用方式规则 前言&#xff1a; 使用Pytest来运行yaml文件来驱动Appium自动化测试是一种方便且灵活的方法。通过将测试数据…

CSS 渐变边框及动画

转载请注明出处&#xff0c;点击此处 查看更多精彩内容 用 CSS 实现渐变边框及动画&#xff0c;下面对关键点进行解释说明&#xff0c;查看完整代码及预览效果请 点击这里。 简单说明原理&#xff1a;使用伪元素 ::before 绘制一个渐变色&#xff0c;然后使用伪元素 ::after 绘…

【数据结构】二叉树详解(2)

⭐️ 前言 ✨ 往期文章链接&#xff1a;二叉树的概念性质 上一篇我们讲了二叉树的结构定义&#xff0c;以及前序/中序/后序的递归遍历&#xff0c;还有一些二叉树的接口实现&#xff0c;本篇我们补充一个二叉树的接口 BinaryTreeDepth。✨上一篇文章链接&#xff1a;二叉树详…

【原创】实现ChatGPT中Transformer模型之Encoder-Decoder

作者&#xff1a;黑夜路人 时间&#xff1a;2023年7月 Transformer Block &#xff08;通用块&#xff09;实现 看以上整个链路图&#xff0c;其实我们可以很清晰看到这心其实在Encoder环节里面主要是有几个大环节&#xff0c;每一层主要的核心作用如下&#xff1a; Multi-he…

出租屋智能电表系统

随着科技的不断发展&#xff0c;智能化逐渐成为人们生活中不可或缺的一部分。在房屋租赁市场中&#xff0c;智能电表系统成为越来越多出租屋的标配&#xff0c;为房东和租户带来了便捷和安全。本文将从以下几个方面介绍出租屋智能电表系统的特点和优势。 一、出租屋智能电表系统…

第二十一章:CCNet:Criss-Cross Attention for Semantic Segmentation ——用于语义分割的交叉注意力

0.摘要 全图像依赖关系为视觉理解问题提供了有用的上下文信息。在这项工作中&#xff0c;我们提出了一种称为Criss-Cross Network&#xff08;CCNet&#xff09;的方法&#xff0c;以更有效和高效的方式获取这种上下文信息。具体而言&#xff0c;对于每个像素&#xff0c;CCNet…

Linux 系统编程-开发环境(二)

目录 7 压缩包管理 7.1 tar 7.2 rar 7.3 zip 8 进程管理 8.1 who 8.2 ps 8.3 jobs 8.4 fg 8.5 bg 8.6 kill 8.7 env 8.8 top 9 用户管理 9.1 创建用户 9.2 设置用户组 9.3 设置密码 9.4 切换用户 9.5 root用户 9.6 删除用户 10 网络管理 10.1 i…

Word之解决中文和英文混写导致字间距增大的问题(六)

简介&#xff1a; CSDN博客专家&#xff0c;专注Android/Linux系统&#xff0c;分享多mic语音方案、音视频、编解码等技术&#xff0c;与大家一起成长&#xff01; 优质专栏&#xff1a;Audio工程师进阶系列【原创干货持续更新中……】&#x1f680; 人生格言&#xff1a; 人生…

机器学习1

核心梯度下降算法&#xff1a; import numpy as np from utils.features import prepare_for_trainingclass LinearRegression:def __init__(self,data,labels,polynomial_degree 0,sinusoid_degree 0,normalize_dataTrue):"""1.对数据进行预处理操作2.先得到…

【iOS】编译与链接

前言 计算机语言分为机器语言、汇编语言和高级语言。 可以将高级语言分为两种&#xff1a;编译语言和解释型语言&#xff08;直译式语言&#xff09;。 解释型语言&#xff08;逐步进行解释执行&#xff09; 解释语言编写的程序在每次运行时都需要通过解释器对程序进行动态…

(四)「消息队列」之 RabbitMQ 路由(使用 .NET 客户端)

0、引言 先决条件 本教程假设 RabbitMQ 已安装并且正在 本地主机 的标准端口&#xff08;5672&#xff09;上运行。如果您使用了不同的主机、端口或凭证&#xff0c;则要求调整连接设置。 获取帮助 如果您在阅读本教程时遇到问题&#xff0c;可以通过邮件列表或者 RabbitMQ 社区…

图数据库:neo4j学习笔记

参考资料&#xff1a;neo4j 教程_w3cschool Springboot集成Neo4j_喝醉的咕咕鸟的博客-CSDN博客 SpringBoot 整合 Neo4j_springboot neo4j_$懒小猿$的博客-CSDN博客 图数据库Neo4j实战&#xff08;全网最详细教程&#xff09;_neo4j使用教程_星川皆无恙的博客-CSDN博客 代码片段…

【个人笔记】linux的cd命令与目录结构理解

cd命令 cd&#xff08;英文全拼&#xff1a;change directory&#xff09;命令用于改变当前工作目录的命令&#xff0c;切换到指定的路径。 若目录名称省略&#xff0c;则变换至使用者的 home 目录 (也就是刚 login 时所在的目录)。 另外&#xff0c;~ 也表示为 home 目录 的…

flask基本用法小白教程+按钮跳转到指定页面+python和pip安装(后附)

一、flask学习教程&#xff1a; 1.1 基本程序&#xff1a; 大家可以在pycharm中复制如下代码&#xff0c;先感受一下flask的基本用法&#xff1a; 点击链接可进入浏览器查看程序运行的结果&#xff0c;在127.0.0.1:5000后面添上/test1/等设定的文字&#xff0c;可查看不同函…

Flutter:网络图像缓存插件——cached_network_image

前言 为什么要使用这个插件&#xff0c;有什么用呢&#xff1f;毕竟官方提供了Image.network来进行网络图片加载 Image.network和CachedNetworkImage都可以用于在Flutter中加载网络图片&#xff0c;但它们之间有一些区别。 Image.network是Flutter核心库提供的一个构造函数&…

Python教程(4)——Python开发工具PyCharm的下载与安装

PyCharm是一种专业的Python集成开发环境&#xff08;IDE&#xff09;&#xff0c;由JetBrains公司开发和维护。它提供了丰富的功能和工具&#xff0c;帮助开发人员更高效地编写、调试和测试Python代码。如果是一些大型Python项目强烈推荐用这个来开发。今天我们来介绍一下PyCha…

Microsoft Update Assistant导致 MAC 电脑内存占用过高解决方案

目录 问题: 排查原因: 解决方案: 问题: 一直很苦恼,每次开机隔会发下电脑内存就 100%了,这次找了下原因,也记录下. 排查原因: 通过 mac 自带的活动监视器,发现居然是Microsoft Update Assistant它导致的 解决方案: 那这样就简单了,这个应该是 word,execl 的一个自动更新程序…

融云出海:不止假发出口和四卡四待手机,「非洲市场」的参差与机遇

↑ 点击预约“融云北极星”直播↑ 点击预约“实时社区”直播 比白皮书更精炼省流&#xff0c;比图谱更实用有效。 融云《社交泛娱乐出海作战地图》&#xff0c;被多位大咖标记为出海人必备工作手册。针对地图的核心模块&#xff0c;我们推出了系列解读文章&#xff0c;更详尽…