淘寶爬取商品資訊以及資料分析
阿新 • • 發佈:2019-02-02
爬取淘寶商品
專案內容
案例選擇>>商品類目:沙發
數量:共100頁 4400商品
篩選條件:天貓、銷量從高到低、價格500元以上
專案目的
- 對商品標題進行文字分析,詞雲視覺化
- 不同關鍵詞word對應的sales的統計分析
- 商品的價格分佈情況分析
- 商品的銷量分佈情況分析
- 不同價格區間的商品的平均銷量分佈
- 商品價格對銷量的影響分析
- 商品價格對銷售額的影響分析
- 不同省份的商品平均銷售分佈
專案步驟
- 資料採集: Python爬取淘寶網商品資料
- 對資料進行清洗和處理
- 文字分析:jieba分詞,wordcloud視覺化
- 資料柱形圖視覺化barh
- 資料直方圖視覺化hist
- 資料散點圖視覺化scatter
- 資料迴歸分析視覺化regplot
模組
requests、retrying、missingno、jieba、matplotlib、wordcloud、imread、seaborn等
一、爬取資料
淘寶網是反爬蟲的,雖然使用多執行緒、修改headers引數,但仍然不能保證每次100%爬取,所以增加了迴圈爬取,每次爬取未爬取成功的頁面,直至所有頁都爬取成功停止。
淘寶商品頁為json格式,使用正則表示式進行解析
# -*- coding: utf-8 -*-
import re
import xlwt
import time
import requests
import pandas as pd
from retrying import retry
from concurrent.futures import ThreadPoolExecutor
import matplotlib
%matplotlib inline
# 計時開始
start = time.clock()
# plist 為1-100頁的URL的編號num
plist = []
for i in range(1, 101):
j = 44 * (i-1)
plist.append(j)
listno = plist
datatmsp = pd.DataFrame(columns=[])
while True:
# 設定最大重試次數
@retry(stop_max_attempt_number = 8)
def network_programming(num):
url = 'https://s.taobao.com/search?initiative_id=tbindexz_20170306&ie=utf8&spm=a21bo.2017.201856-taobao-item.2&sourceId=tb.index&search_type=item&ssid=s5-e&commend=all&imgfile=&q=%E6%B2%99%E5%8F%91&suggest=history_1&_input_charset=utf-8&wq=shafa&suggest_query=shafa&source=suggest&bcoffset=4&ntoffset=4&p4ppushleft=1%2C48&s=' + str(num)
web = requests.get(url, headers=headers)
web.encoding = 'utf-8'
return web
# 多執行緒
def multithreading():
# 每次爬取未爬取成功的頁
number = listno
event = []
with ThreadPoolExecutor(max_workers=10) as executor:
for result in executor.map(network_programming, number, chunksize=10):
event.append(result)
return event
headers = {
'User-Agent':'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.167 Safari/537.36'
}
listpg = []
event = multithreading()
for i in event:
json = re.findall(
'"auctions":(.*?),"recommendAuctions"', i.text)
if len(json):
table = pd.read_json(json[0])
datatmsp = pd.concat([datatmsp, table],
axis=0, ignore_index=True)
pg = re.findall(
'"pageNum":(.*?),"p4pbottom_up"', i.text)[0]
listpg.append(pg)
lists = []
for a in listpg:
b = 44 * (int(a)-1)
lists.append(b)
listn = listno
listno = []
for p in listn:
if p not in lists:
listno.append(p)
if len(listno) == 0:
break
datatmsp.to_excel('./data/datastmsp.xls', index=False)
end = time.clock()
print("爬取完成,用時: ",end-start, 's')
爬取完成,用時: 9.088245 s
二、資料清洗,處理
datatmsp = pd.read_excel('./data/datastmsp.xls')
datatmsp.shape
(4392, 25)
import missingno as msno
msno.bar(datatmsp.sample(len(datatmsp)), figsize=(10, 4))
# 刪除缺失值過半的列
half_count = len(datatmsp)/2
datatmsp = datatmsp.dropna(thresh=half_count, axis=1)
datatmsp = datatmsp.drop_duplicates()
![png](https://raw.githubusercontent.com/Roc-J/Machine-Learning/master/taobao_goods_analysis/images/output_6_0.png)
datatmsp.head()
.dataframe tbody tr th:only-of-type {
vertical-align: middle;
}
.dataframe tbody tr th {
vertical-align: top;
}
.dataframe thead th {
text-align: right;
}
category | comment_count | comment_url | detail_url | i2iTags | icon | item_loc | nick | nid | p4pTags | pic_url | pid | raw_title | shopLink | shopcard | title | user_id | view_fee | view_price | view_sales | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | NaN | NaN | https://click.simba.taobao.com/cc_im?p=%C9%B3%… | https://click.simba.taobao.com/cc_im?p=%C9%B3%… | NaN | [{‘title’: ‘掌櫃熱賣寶貝’, ‘url’: ‘//re.taobao.com/s… | 廣東 佛山 | 林氏木業傢俱旗艦店 | 556041494716 | NaN | //g-search1.alicdn.com/img/bao/uploaded/i4/img… | NaN | 北歐風格小戶型實木架客廳L型布藝沙發組合 | https://click.simba.taobao.com/cc_im?p=%C9%B3%… | {‘isTmall’: True, ‘delivery’: [0, 1, 2007], ‘s… | 林氏木業<span class=H>沙發</span>北歐傢俱小戶型實木框客廳現代簡約布藝<… | 143584903 | 0.0 | 3480.0 | 328人付款 |
1 | 50020633.0 | 430.0 | //detail.tmall.com/item.htm?id=528317610670&ad… | //detail.tmall.com/item.htm?id=528317610670&ad… | {‘samestyle’: {‘url’: ‘/search?type=samestyle&… | [{‘title’: ‘尚天貓,就購了’, ‘url’: ‘//www.tmall.com/… | 廣東 佛山 | 凱哲傢俱旗艦店 | 528317610670 | [] | //g-search3.alicdn.com/img/bao/uploaded/i4/i3/… | -1.038122e+09 | 凱哲傢俱歐式真皮沙發 頭層牛皮雕花實木客廳整裝轉角沙發組合 | //store.taobao.com/shop/view_shop.htm?user_num… | {‘isTmall’: True, ‘totalRate’: 10000, ‘deliver… | 凱哲傢俱歐式真皮<span class=H>沙發</span> 頭層牛皮雕花實木客廳整裝轉角… | 867828093 | 0.0 | 7400.0 | 111人付款 |
2 | 50020633.0 | 434.0 | //detail.tmall.com/item.htm?id=534013594681&ad… | //detail.tmall.com/item.htm?id=534013594681&ad… | {‘samestyle’: {‘url’: ‘/search?type=samestyle&… | [{‘title’: ‘尚天貓,就購了’, ‘url’: ‘//www.tmall.com/… | 廣東 佛山 | 雅居匯旗艦店 | 534013594681 | [] | //g-search2.alicdn.com/img/bao/uploaded/i4/i2/… | -1.255613e+09 | 雅居匯 歐式真皮轉角沙發實木雕花客廳傢俱組合美式真皮轉角沙發 | //store.taobao.com/shop/view_shop.htm?user_num… | {‘isTmall’: True, ‘totalRate’: 10000, ‘deliver… | 雅居匯 歐式真皮轉角<span class=H>沙發</span>實木雕花客廳傢俱組合美式真… | 1696287283 | 0.0 | 18800.0 | 25人付款 |
3 | 50020633.0 | 868.0 | //detail.tmall.com/item.htm?id=45828269874&ns=… | //detail.tmall.com/item.htm?id=45828269874&ns=… | {‘samestyle’: {‘url’: ”}, ‘similar’: {‘url’: … | [{‘title’: ‘尚天貓,就購了’, ‘url’: ‘//www.tmall.com/… | 廣東 江門 | 斯帝羅蘭傢俱旗艦店 | 45828269874 | [] | //g-search1.alicdn.com/img/bao/uploaded/i4/i3/… | -1.774408e+09 | 斯帝羅蘭簡約現代真皮沙發組合整裝客廳轉角頭層牛皮三人沙發傢俱 | //store.taobao.com/shop/view_shop.htm?user_num… | {‘isTmall’: True, ‘totalRate’: 10000, ‘deliver… | 斯帝羅蘭簡約現代真皮<span class=H>沙發</span>組合整裝客廳轉角頭層牛皮三… | 2485585242 | 800.0 | 8699.0 | 93人付款 |
4 | 50020632.0 | 81.0 | //detail.tmall.com/item.htm?id=560306420180&ns… | //detail.tmall.com/item.htm?id=560306420180&ns… | {‘samestyle’: {‘url’: ‘/search?type=samestyle&… | [{‘title’: ‘尚天貓,就購了’, ‘url’: ‘//www.tmall.com/… | 浙江 杭州 | kuka顧家家居旗艦店 | 560306420180 | [] | //g-search3.alicdn.com/img/bao/uploaded/i4/i3/… | -1.912232e+09 | !【新款】現顧家kuka北歐布藝沙發客廳大小戶型現代簡約組合2037 | //store.taobao.com/shop/view_shop.htm?user_num… | {‘isTmall’: True, ‘totalRate’: 10000, ‘deliver… | !【新款】現顧家kuka北歐布藝<span class=H>沙發</span>客廳大小戶型現… | 2096542875 | 0.0 | 2999.0 | 142人付款 |
根據需求,本案例 item_loc, raw_title, view_price, view_sales 標題,區域,價格,銷量分析
data = datatmsp[
['item_loc', 'raw_title', 'view_price', 'view_sales']
]
data.head()
.dataframe tbody tr th:only-of-type {
vertical-align: middle;
}
.dataframe tbody tr th {
vertical-align: top;
}
.dataframe thead th {
text-align: right;
}
item_loc | raw_title | view_price | view_sales | |
---|---|---|---|---|
0 | 廣東 佛山 | 北歐風格小戶型實木架客廳L型布藝沙發組合 | 3480.0 | 328人付款 |
1 | 廣東 佛山 | 凱哲傢俱歐式真皮沙發 頭層牛皮雕花實木客廳整裝轉角沙發組合 | 7400.0 | 111人付款 |
2 | 廣東 佛山 | 雅居匯 歐式真皮轉角沙發實木雕花客廳傢俱組合美式真皮轉角沙發 | 18800.0 | 25人付款 |
3 | 廣東 江門 | 斯帝羅蘭簡約現代真皮沙發組合整裝客廳轉角頭層牛皮三人沙發傢俱 | 8699.0 | 93人付款 |
4 | 浙江 杭州 | !【新款】現顧家kuka北歐布藝沙發客廳大小戶型現代簡約組合2037 | 2999.0 | 142人付款 |
# 對城市進行分割,把省份和城市區別
# 對銷售額進行
data['province'] = data.item_loc.apply(lambda x:x.split()[0])
data['city'] = data.item_loc.apply(lambda x:x.split()[0] if len(x)<4 else x.split()[1])
data['sales'] = data.view_sales.apply(lambda x:x.split('人')[0])
data.dtypes
/usr/local/lib/python3.5/dist-packages/ipykernel_launcher.py:3: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy
This is separate from the ipykernel package so we can avoid doing imports until
/usr/local/lib/python3.5/dist-packages/ipykernel_launcher.py:4: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy
after removing the cwd from sys.path.
/usr/local/lib/python3.5/dist-packages/ipykernel_launcher.py:6: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy
item_loc object
raw_title object
view_price float64
view_sales object
province object
city object
sales object
dtype: object
data['sales'] = data.sales.astype('int')
list_col = ['province', 'city']
for i in list_col:
data[i] = data[i].astype('category')
data = data.drop(['item_loc', 'view_sales'], axis=1)
/usr/local/lib/python3.5/dist-packages/ipykernel_launcher.py:1: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy
“”“Entry point for launching an IPython kernel.
/usr/local/lib/python3.5/dist-packages/ipykernel_launcher.py:4: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy
after removing the cwd from sys.path.
data.head()
.dataframe tbody tr th:only-of-type {
vertical-align: middle;
}
.dataframe tbody tr th {
vertical-align: top;
}
.dataframe thead th {
text-align: right;
}
raw_title | view_price | province | city | sales | |
---|---|---|---|---|---|
0 | 北歐風格小戶型實木架客廳L型布藝沙發組合 | 3480.0 | 廣東 | 佛山 | 328 |
1 | 凱哲傢俱歐式真皮沙發 頭層牛皮雕花實木客廳整裝轉角沙發組合 | 7400.0 | 廣東 | 佛山 | 111 |
2 | 雅居匯 歐式真皮轉角沙發實木雕花客廳傢俱組合美式真皮轉角沙發 | 18800.0 | 廣東 | 佛山 | 25 |
3 | 斯帝羅蘭簡約現代真皮沙發組合整裝客廳轉角頭層牛皮三人沙發傢俱 | 8699.0 | 廣東 | 江門 | 93 |
4 | !【新款】現顧家kuka北歐布藝沙發客廳大小戶型現代簡約組合2037 | 2999.0 | 浙江 | 杭州 | 142 |
資料探勘和分析
使用jieba
對列標題進行文字分析
title = data.raw_title.values.tolist()
import jieba
title_s = []
for line in title:
title_cut = jieba.lcut(line)
title_s.append(title_cut)
# 剔除不需要的單詞,使用停用表
stopwords = pd.read_excel('./data/stopwords.xlsx')
stopwords = stopwords.stopword.values.tolist()
title_clean = []
for line in title_s:
line_clean = []
for word in line:
if word not in stopwords:
line_clean.append(word)
title_clean.append(line_clean)
# 統計每個詞語的個數,先去重
title_clean_dist = []
for line in title_clean:
line_dist = []
for word in line:
if word not in line_dist:
line_dist.append(word)
title_clean_dist.append(line_dist)
# 將所有詞轉換為一個list
allwords_clean_dist = []
for line in title_clean_dist:
for word in line:
allwords_clean_dist.append(word)
# 將所有詞語轉換資料框
df_allwords_clean_dist = pd.DataFrame({
'allwords': allwords_clean_dist
})
word_count = df_allwords_clean_dist.allwords.value_counts().reset_index()
word_count.columns = ['word', 'count']
word_count.head()
Building prefix dict from the default dictionary …
Loading model from cache /tmp/jieba.cache
Loading model cost 0.644 seconds.
Prefix dict has been built succesfully.
.dataframe tbody tr th:only-of-type {
vertical-align: middle;
}
.dataframe tbody tr th {
vertical-align: top;
}
.dataframe thead th {
text-align: right;
}
word | count | |
---|---|---|
0 | 沙發 | 2897 |
1 | 組合 | 2800 |
2 | 客廳 | 2570 |
3 | 小戶型 | 2348 |
4 | 簡約 | 1908 |
詞雲視覺化
需要wordcloud
from wordcloud import WordCloud
import matplotlib.pyplot as plt
from scipy.misc import imread
plt.figure(figsize=(20,10))
pic = imread("./images/shafa.jpg")
w_c = WordCloud(font_path="./data/simhei.ttf",
background_color='white',
mask=pic,
max_font_size=60,
margin=1)
wc = w_c.fit_words({
x[0]:x[1] for x in word_count.head(100).values
})
plt.imshow(wc, interpolation='bilinear')
plt.axis("off")
plt.show()
/usr/local/lib/python3.5/dist-packages/ipykernel_launcher.py:6: DeprecationWarning: `imread` is deprecated!
`imread` is deprecated in SciPy 1.0.0, and will be removed in 1.2.0.
Use “imageio.imread“ instead.
![png](https://raw.githubusercontent.com/Roc-J/Machine-Learning/master/taobao_goods_analysis/images/output_16_1.png)
分析結論:
1. 客廳、組合、沙發、整裝商品佔比很高
2. 從沙發材質 布藝沙發佔比高
3. 從沙發風格看,簡約風格最多
4. 從戶型看,小戶型
不同關鍵詞對應sales進統計分析
例如,詞語簡約,則統計商品中含有簡約一詞的商品的銷售之和
import numpy as np
w_s_sum = []
for w in word_count.word:
i = 0
s_list = []
for t in title_clean_dist:
if w in t:
try:
s_list.append(data.sales[i])
except:
s_list.append(0)
i += 1
w_s_sum.append(sum(s_list))
df_w_s_sum = pd.DataFrame({'w_s_sum':w_s_sum})
df_w_s_sum.head()
.dataframe tbody tr th:only-of-type {
vertical-align: middle;
}
.dataframe tbody tr th {
vertical-align: top;
}
.dataframe thead th {
text-align: right;
}
w_s_sum | |
---|---|
0 | 354926 |
1 | 347685 |
2 | 342496 |
3 | 314679 |
4 | 275670 |
word_count.head()
.dataframe tbody tr th:only-of-type {
vertical-align: middle;
}
.dataframe tbody tr th {
vertical-align: top;
}
.dataframe thead th {
text-align: right;
}
word | count | |
---|---|---|
0 | 沙發 | 2897 |
1 | 組合 | 2800 |
2 | 客廳 | 2570 |
3 | 小戶型 | 2348 |
4 | 簡約 | 1908 |
df_word_sum = pd.concat([word_count, df_w_s_sum],
axis=1,
ignore_index=True)
df_word_sum.columns = ['word', 'count', 'w_s_sum']
df_word_sum.head(30)
.dataframe tbody tr th:only-of-type {
vertical-align: middle;
}
.dataframe tbody tr th {
vertical-align: top;
}
.dataframe thead th {
text-align: right;
}
word | count | w_s_sum | |
---|---|---|---|
0 | 沙發 | 2897 | 354926 |
1 | 組合 | 2800 | 347685 |
2 | 客廳 | 2570 | 342496 |
3 | 小戶型 | 2348 | 314679 |
4 | 簡約 | 1908 | 275670 |
5 | 布藝沙發 | 1711 | 246148 |
6 | 整裝 | 1508 | 241084 |
7 | 傢俱 | 1164 | 179426 |
8 | 轉角 | 1129 | 161985 |
9 | 實木 | 1037 | 85924 |
10 | 拆洗 | 1017 | 172892 |
11 | 北歐 | 980 | 113124 |
12 | 876 | 117483 | |
13 | 真皮沙發 | 672 | 85379 |
14 | 歐式 | 669 | 53565 |
15 | 三人 | 605 | 73091 |
16 | 美式 | 564 | 51658 |
17 | 中式 | 514 | 35921 |
18 | 貴妃 | 476 | 44932 |
19 | 頭層 | 439 | 63404 |
20 | 新 | 435 | 32108 |
21 | 牛皮 | 429 | 62568 |
22 | 雙人 | 368 | 40741 |
23 | 客廳傢俱 | 367 | 33210 |
24 | 單人 | 364 | 38327 |
25 | 三人位 | 326 | 33263 |
26 | 皮藝 | 300 | 33529 |
27 | 布 | 278 | 52697 |
28 | 乳膠 | 274 | 32451 |
29 | 布藝 | 271 | 28038 |
視覺化資料
df_word_sum.sort_values('w_s_sum',
inplace=True,
ascending=True)
df_w_s = df_word_sum.tail(30)
import matplotlib
from matplotlib import pyplot as plt
font = matplotlib.font_manager.FontProperties(fname='./data/simhei.ttf')
index = np.arange(df_w_s.word.size)
plt.figure(figsize=(6,12))
plt.barh(index,
df_w_s.w_s_sum,
color='blue',
align='center',
alpha=0.8)
plt.yticks(index, list(df_w_s.word), fontproperties=font)
for y,x in zip(index, df_w_s.w_s_sum):
plt.text(x,y,"%.0f" %x, ha='left', va='center')
plt.show()
![png](https://raw.githubusercontent.com/Roc-J/Machine-Learning/master/taobao_goods_analysis/images/output_24_0.png)
商品的價格分佈情況分析
分析價格小於20000的商品
data.head()
.dataframe tbody tr th:only-of-type {
vertical-align: middle;
}
.dataframe tbody tr th {
vertical-align: top;
}
.dataframe thead th {
text-align: right;
}
raw_title | view_price | province | city | sales | |
---|---|---|---|---|---|
0 | 北歐風格小戶型實木架客廳L型布藝沙發組合 | 3480.0 | 廣東 | 佛山 | 328 |
1 | 凱哲傢俱歐式真皮沙發 頭層牛皮雕花實木客廳整裝轉角沙發組合 | 7400.0 | 廣東 | 佛山 | 111 |
2 | 雅居匯 歐式真皮轉角沙發實木雕花客廳傢俱組合美式真皮轉角沙發 | 18800.0 | 廣東 | 佛山 | 25 |
3 | 斯帝羅蘭簡約現代真皮沙發組合整裝客廳轉角頭層牛皮三人沙發傢俱 | 8699.0 | 廣東 | 江門 | 93 |
4 | !【新款】現顧家kuka北歐布藝沙發客廳大小戶型現代簡約組合2037 | 2999.0 | 浙江 | 杭州 | 142 |
data_p = data[data['view_price'] < 20000]
plt.figure(figsize=(7, 5))
plt.hist(data_p['view_price'], bins=15, color='purple')
plt.xlabel(u'價格', fontproperties=font)
plt.ylabel(u'商品數量', fontproperties=font)
plt.title(u'不同價格對應的商品資料分佈', fontproperties=font)
plt.show()
![png](https://raw.githubusercontent.com/Roc-J/Machine-Learning/master/taobao_goods_analysis/images/output_27_0.png)
1. 由圖表可知:商品數量隨著價格總體呈現下降階梯形勢,價格越高,在售的商品越少
商品的銷量分佈情況分析
同樣,為了使視覺化效果更加直觀,這裡我們選擇銷量大於100的商品
data_s = data[(data['sales'] > 100) & (data['sales'] < 2000)]
print(u'銷量100以上的商品佔比 : %0.3f' % (len(data_s)/len(data)))
plt.figure(figsize=(7, 5))
plt.hist(data_s['sales'], bins=20, color='blue')
plt.xlabel(u'銷量', fontproperties=font)
plt.ylabel(u'商品數量', fontproperties=font)
plt.title(u'不同銷量對應的商品資料分佈', fontproperties=font)
plt.show()
銷量100以上的商品佔比 : 0.271
![png](https://raw.githubusercontent.com/Roc-J/Machine-Learning/master/taobao_goods_analysis/images/output_30_1.png)
根據圖表可知:
1. 銷量100以上的商品僅佔3.4%,其中銷量100-200商品最多,200-300次之
2. 銷量100-500之間,商品的數量隨著銷量呈現下降趨勢,且趨勢陡峭,低銷量商品居多;
3. 銷量750以上的商品很少。
不同價格區間的商品平均銷量分佈
data['price'] = data.view_price.astype('int')
data['group'] = pd.qcut(data.price, 12)
df_group = data.group.value_counts().reset_index()
df_s_g = data[
['sales','group']
].groupby('group').mean().reset_index()
df_s_g
.dataframe tbody tr th:only-of-type {
vertical-align: middle;
}
.dataframe tbody tr th {
vertical-align: top;
}
.dataframe thead th {
text-align: right;
}
group | sales | |
---|---|---|
0 | (39.999, 490.0] | 331.904437 |
1 | (490.0, 888.0] | 141.583618 |
2 | (888.0, 1198.0] | 244.261168 |
3 | (1198.0, 1580.0] | 184.880368 |
4 | (1580.0, 1891.0] | 158.511628 |
5 | (1891.0, 2368.0] | 99.013559 |
6 | (2368.0, 2880.0] | 141.297659 |
7 | (2880.0, 3480.0] | 116.955782 |
8 | (3480.0, 4180.0] | 59.924460 |
9 | (4180.0, 5300.0] | 38.013378 |
10 | (5300.0, 7290.0] | 36.003509 |
11 | (7290.0, 99002.0] | 27.580756 |
index = np.arange(df_s_g.group.size)
plt.figure(figsize=(8,4))
plt.bar(index, df_s_g.sales, color='blue')
plt.xticks(index, df_s_g.group, fontproperties=font, rotation=30)
plt.xlabel('Group')
plt.ylabel('mean_sales')
plt.title(u'不同價格商品的平均銷量',fontproperties=font)
plt.show()
![png](https://raw.githubusercontent.com/Roc-J/Machine-Learning/master/taobao_goods_analysis/images/output_34_0.png)
由圖表可知:
1. 價格在40-490之間的商品平均銷量最高,888-1198之間的次之,7290元以上的最低;
2. 總體呈現減的趨勢
商品價格對銷量的影響分析
data_p
.dataframe tbody tr th:only-of-type {
vertical-align: middle;
}
.dataframe tbody tr th {
vertical-align: top;
}
.dataframe thead th {
text-align: right;
}
raw_title | view_price | province | city | sales | |
---|---|---|---|---|---|
0 | 北歐風格小戶型實木架客廳L型布藝沙發組合 | 3480.00 | 廣東 | 佛山 | 328 |
1 | 凱哲傢俱歐式真皮沙發 頭層牛皮雕花實木客廳整裝轉角沙發組合 | 7400.00 | 廣東 | 佛山 | 111 |
2 | 雅居匯 歐式真皮轉角沙發實木雕花客廳傢俱組合美式真皮轉角沙發 | 18800.00 | 廣東 | 佛山 | 25 |
3 | 斯帝羅蘭簡約現代真皮沙發組合整裝客廳轉角頭層牛皮三人沙發傢俱 | 8699.00 | 廣東 | 江門 | 93 |
4 | !【新款】現顧家kuka北歐布藝沙發客廳大小戶型現代簡約組合2037 | 2999.00 | 浙江 | 杭州 | 142 |
5 | !現顧家kuka布藝沙發客廳整裝北歐傢俱現代簡約布沙發2033 | 4399.00 | 浙江 | 杭州 | 128 |
6 | !現顧家布藝沙發客廳整裝現代簡約可拆洗小戶型皮布沙發B001-1 | 4399.00 | 浙江 | 杭州 | 64 |
7 | 軒億北歐布藝沙發大小戶型組合客廳現代簡約轉角三人沙發整裝傢俱 | 2688.00 | 廣東 | 佛山 | 470 |
8 | 布藝沙發客廳整裝現代簡約123組合傢俱套裝經濟型沙發小戶型一田 | 1280.00 | 廣東 | 佛山 | 2489 |
9 | 北歐沙發小戶型雙人簡約日式布藝實木小型休閒簡易臥室迷你單人椅 | 127.80 | 浙江 | 湖州 | 1516 |
10 | 思茵美現代簡約客廳真皮沙發組合整裝 大小戶型轉角頭層牛皮沙發 | 3480.00 | 廣東 | 佛山 | 185 |
11 | 現貨!現代防水布藝沙發可拆洗整裝小戶型公寓客廳乳膠三人位沙發 | 1490.00 | 廣東 | 佛山 | 748 |
12 | 新款布藝沙發簡約現代小戶型組合客廳傢俱可拆洗轉角三人位布沙發 | 898.20 | 廣東 | 佛山 | 1669 |
13 | 新款布藝沙發簡約現代小戶型三人位貴妃沙發拆洗客廳整裝組合沙發 | 899.00 | 廣東 | 佛山 | 1064 |
14 | 林爾邦簡約現代布藝沙發組合大小戶型可拆洗乳膠轉角客廳整裝傢俱 | 1580.00 | 廣東 | 佛山 | 262 |
15 | 拆洗布藝沙發現代簡約客廳小戶型沙發三人位組合傢俱整裝轉角沙發 | 778.00 | 廣東 | 佛山 | 549 |
17 | 北歐沙發實木小戶型客廳現代簡約 羽絨乳膠布藝沙發組合整裝傢俱 | 2713.20 | 廣東 | 佛山 | 192 |
18 | 小戶型簡約現代布藝沙發日式單人簡易辦公室沙發椅北歐雙三人組合 | 158.00 | 浙江 | 湖州 | 3210 |
19 | 新中式沙發現代禪意客廳實木沙發組合樣板房酒店復古傢俱布藝沙發 | 1980.00 | 江蘇 | 蘇州 | 179 |
20 | 北歐實木單人雙人三人簡約日式沙發椅客廳布藝現代簡易小戶型沙發 | 127.50 | 浙江 | 湖州 | 2167 |
21 | 歐式真皮沙發實木雕花轉角客廳頭層牛皮123組合小戶型仿古色傢俱 | 4580.00 | 廣東 | 佛山 | 203 |
22 | 布藝沙發組合可拆洗簡約現代大小戶型三人客廳轉角時尚整裝傢俱 | 1180.00 | 廣東 | 佛山 | 558 |
23 | 布雷爾頭層牛皮真皮沙發簡約現代皮藝沙發大戶型客廳整裝沙發組合 | 3580.00 | 廣東 | 佛山 | 298 |
24 | 布雷爾可拆洗布藝沙發組合簡約現代客廳傢俱整裝u型布沙發茶几 | 1680.00 | 廣東 | 佛山 | 443 |
25 | 布藝沙發簡約現代大小戶型客廳轉角可拆洗布沙發組合整裝傢俱 | 1138.00 | 廣東 | 佛山 | 1788 |
26 | 簡約現代布藝沙發小戶型組合客廳傢俱轉角多色三人位布沙發可拆洗 | 898.20 | 廣東 | 佛山 | 2089 |
27 | 布藝沙發組合 現代客廳大小戶型可拆洗皮沙發北歐u型貴妃整裝傢俱 | 2180.00 | 廣東 | 佛山 | 397 |
28 | 布藝沙發組合中小戶型客廳整裝現代簡約套裝可拆洗經濟型組裝傢俱 | 1180.00 | 廣東 | 佛山 | 202 |
29 | 布藝沙發可拆洗組合客廳田園整裝三人位小戶型簡約現代選貴妃傢俱 | 1480.00 | 廣東 | 佛山 | 104 |
30 | 實木單雙人布藝沙發咖啡廳卡座網咖沙發椅小戶型沙發單人北歐沙發 | 158.00 | 浙江 | 湖州 | 2058 |
… | … | … | … | … | … |
4347 | 歐式布藝沙發組合雙貴妃U型奢華實木客廳整裝高檔轉角簡歐沙發 | 5356.80 | 廣東 | 佛山 | 24 |
4349 | 百方傢俱 小戶型布藝沙發轉角可拆洗北歐沙發套裝客廳整裝組合 | 1980.00 | 廣東 | 佛山 | 107 |
4351 | 凱菲斯品牌北歐布藝沙發 三人位客廳組合 小戶型羽絨乳膠整裝沙發 | 2199.00 | 廣東 | 佛山 | 146 |
4352 | 韓興傢俱 現代小戶型布藝沙發轉角可拆洗套裝沙發客廳整裝組合 | 1380.00 | 廣東 | 佛山 | 185 |
4355 | 辦公沙發 中式大款洽談會客商務接待沙發 真皮三人位辦公室沙發 | 4680.00 | 廣東 | 佛山 | 114 |
4356 | 布藝沙發組合客廳配套大小戶型簡約現代整裝傢俱U多功能皮布沙發 | 1280.00 | 廣東 | 佛山 | 259 |
4357 | 北歐風格布藝沙發小戶型現代簡約經濟型雙人客廳傢俱整裝組合 | 1680.00 | 廣東 | 佛山 | 248 |
4358 | H.K/皇客 布藝沙發現代簡約客廳整裝可拆洗大小戶型北歐沙發組合 | 1688.88 | 廣東 | 佛山 | 38 |
4360 | 北歐布藝沙發大小戶型可拆洗簡約現代客廳棉麻布沙發轉角組合整裝 | 2188.80 | 廣東 | 佛山 | 45 |
4361 | GKG北歐布藝沙發組合簡約現代大小戶型貴妃沙發客廳整裝傢俱 | 1480.00 | 廣東 | 佛山 | 28 |
4363 | 真皮沙發組合頭層牛皮 大戶型皮藝沙發整裝客廳轉角現代簡約傢俱 | 2790.00 | 廣東 | 佛山 | 46 |
4366 | 辦公室皮沙發甜品奶茶店西餐咖啡廳雙人卡座洽談桌椅組合簡約休閒 | 280.00 | 浙江 | 湖州 | 1006 |
4368 | 北歐風格布藝沙發科技布日式小戶型客廳組合省空間三人位沙發套裝 | 1680.00 | 廣東 | 佛山 | 67 |
4369 | 真皮辦公沙發 中式大款會客商務洽談接待沙發 三人位辦公室沙發 | 4679.50 | 廣東 | 佛山 | 159 |
4370 | 可拆洗簡約現代棉麻布沙發時尚大小戶型客廳轉角布藝沙發組合整裝 | 1468.00 | 廣東 | 佛山 | 43 |
4371 | 新款北歐布藝沙發大小戶型客廳轉角布沙發可拆洗組合簡約傢俱整裝 | 2080.00 | 廣東 | 佛山 | 98 |
4372 | 乳膠布藝沙發組合北歐大小戶型布沙發日式可拆洗沙發現代轉角傢俱 | 1557.24 | 廣東 | 佛山 | 156 |
4373 | 簡約現代客廳大小戶型貴妃L轉角布藝沙發組合可定做尺寸沙發 | 1680.00 | 廣東 | 佛山 | 33 |
4376 | 布藝沙發組合簡約現代三人可拆洗北歐乳膠小戶型沙發客廳整裝傢俱 | 899.00 | 廣東 | 佛山 | 161 |
4378 | 布藝沙發組合大小戶型傢俱簡約現代可拆洗轉角布沙發客廳整裝沙發 | 1880.00 | 廣東 | 佛山 | 86 |
4382 | 北歐布藝沙發組合轉角貴妃大小戶型客廳整裝現代簡約灰色日式沙發 | 2299.00 | 廣東 | 佛山 | 27 |
4383 | 辦公沙發茶几組合商務接待小型沙發現代簡約會客三人位辦公室沙發 | 497.80 | 廣東 | 佛山 | 1331 |
4384 | 布藝沙發大小戶型客廳轉角簡約現代可拆洗L型組合整裝傢俱布沙發 | 1480.00 | 廣東 | 佛山 | 43 |
4385 | 布藝沙發組合可拆洗簡約現代客廳轉角貴妃大小戶L型沙發整裝傢俱 | 1280.00 | 廣東 | 佛山 | 228 |
4386 | 真皮辦公室沙發茶几組合現代簡約高檔三人位商務傢俱接待會客特價 | 1100.00 | 廣東 | 佛山 | 81 |
4387 | 奶茶甜品店咖啡西餐廳洽談桌椅組合現代簡約休閒皮藝雙人卡座沙發 | 280.00 | 浙江 | 湖州 | 230 |
4388 | 北歐簡約布藝沙發大小戶型客廳轉角儲物可拆洗L/U型整裝組合傢俱 | 1980.00 | 廣東 | 佛山 | 125 |
4389 | 美式鄉村復古工藝義大利進口油蠟皮頭層真牛皮沙發1+2+3組合 | 3499.00 | 廣東 | 佛山 | 31 |
4390 | 辦公沙發簡約會客接待商務三人位沙發辦公室傢俱時尚沙發茶几組合 | 558.00 | 廣東 | 佛山 | 942 |
4391 | 洽談桌椅組合簡約休閒甜品奶茶店西餐咖啡廳雙人卡座辦公室布沙發 | 200.00 | 浙江 | 湖州 | 1323 |
3449 rows × 5 columns
fig, ax = plt.subplots()
ax.scatter(data_p['view_price'],data_p['sales'], color='red')
ax.set_xlabel(u'價格')
ax.set_ylabel(u'銷量')
ax.set_title(u'商品價格對銷量的影響',fontproperties=font)
plt.show()
商品價格對銷售額的影響
data['GMV'] = data['price'] * data['sales']
import seaborn as sns
sns.regplot(x='price', y='GMV', data=data, color='purple')
<matplotlib.axes._subplots.AxesSubplot at 0x7f7364ef8080>
由圖表可知:
總體趨勢:由線性迴歸擬合線可以看出,商品銷售額隨著價格增長呈現上升趨勢;
多數商品的價格偏低,銷售額也偏低;
不同省份商品數量分佈
plt.figure(figsize=(8,4))
data.province.value_counts().plot(kind='bar', color='blue')
plt.xticks(rotation=0,fontproperties=font)
plt.xlabel(u'省份',fontproperties=font)
plt.ylabel(u'數量',fontproperties=font)
plt.title(u'不同價格商品的平均銷量',fontproperties=font)
plt.show()
由圖表可知:
廣東的最多,浙江次之,江蘇第三,尤其是廣東的數量遠超過江蘇、浙江、上海等地,說明在沙發這個子類目,廣東的店鋪占主導地位;
江浙滬等地的數量差異不大,基本相當。