您好,登錄后才能下訂單哦!
本篇內容介紹了“如何用Pyecharts生成云詞”的有關知識,在實際案例的操作過程中,不少人都會遇到這樣的困境,接下來就讓小編帶領大家學習一下如何處理這些情況吧!希望大家仔細閱讀,能夠學有所成!
首先我們得先了解兩個概念——上胸圍 & 下胸圍,具體看示意圖:
通過上胸圍與下胸圍的差值,我們就可以確定罩杯的大小了,具體的對應關系可參考下圖:
有了下胸圍 & 罩杯就能確定文胸對應的尺碼了~
當然這又有分為英式尺碼和國際尺碼,具體參考下圖:
from pyecharts.charts import *from pyecharts import options as optsfrom pyecharts.commons.utils import JsCodefrom collections import Counterimport reimport pandas as pdimport jiebaimport jieba.posseg as psgfrom stylecloud import gen_stylecloudfrom IPython.display import Image
原始數據是txt格式,為了方便處理,這邊轉為Dataframe~
尺碼部分通過正則表達式提取出對應的下胸圍和罩杯,具體代碼如下:
In [2]:
patterns = re.compile(r'(?P<datetime>.*),顏色分類:(?P<color>.*?);尺碼:(?P<size>.*?),(?P<comment>.*)')with open('/home/kesci/input/cup6439/cup_all.txt', 'r') as f: data = f.readlines()obj_list = []for item in data: obj = patterns.search(item) obj_list.append(obj.groupdict()) data = pd.DataFrame(obj_list)data = pd.concat([data, data['size'].str.extract('(?P<circumference>[7-9]{1}[0|5]{1}).*(?P<cup>[a-zA-Z])', expand=True)], axis=1)data.head()
Out[2]:
color | comment | datetime | size | circumference | cup | |
---|---|---|---|---|---|---|
0 | 膚色薄款 | 不錯給婆婆買的,準備再買兩件 | 2017-04-20 13:06:04 | 38/85C | 85 | C |
1 | H007寶藍色加粉色 | 和想象的一樣好!價格實惠!攏胸效果很好穿著舒服,就是我要的是寶藍加膚色!給發了一件粉色,也不... | 2017-04-23 21:44:20 | 34/75B | 75 | B |
2 | 超薄杯純潔白 | 真的不錯 | 2017-05-18 10:36:31 | 80C | 80 | C |
3 | 淺紫 | 一次買了兩件,內衣質量不錯,無鋼圈設計穿上很舒服也很有型,值得購買。 | 2017-04-19 20:44:51 | 36B=80B | 80 | B |
4 | 卡其色 | 因為手機號填錯了結果直接被退件了_(:_」∠)_但是賣家還是超好心地給我重新送了回來qwq | 2017-05-07 09:16:47 | 75A | 75 | A |
我們通過jieba
分詞來看看商品分類中最常出現的是哪些關鍵詞~
顏色:膚色 > 黑色 > 粉色 > 白色;
薄款 > 厚款;
鋼圈似乎是個比較重要的賣點;
In [3]:
w_all = []for item in data.color: w_l = psg.cut(item) w_l = [w for w, f in w_l if f in ('n', 'nr') and len(w)>1] w_all.extend(w_l)c = Counter(w_all)
Building prefix dict from the default dictionary ... Dumping model to file cache /tmp/jieba.cache Loading model cost 0.769 seconds. Prefix dict has been built succesfully.
In [4]:
counter = c.most_common(50)bar = (Bar(init_opts=opts.InitOpts(theme='purple-passion', width='1000px', height='800px')) .add_xaxis([x for x, y in counter[::-1]]) .add_yaxis('出現次數', [y for x, y in counter[::-1]], category_gap='30%') .set_global_opts(title_opts=opts.TitleOpts(title="出現最多的關鍵詞", pos_left="center", title_textstyle_opts=opts.TextStyleOpts(font_size=20)), datazoom_opts=opts.DataZoomOpts(range_start=70, range_end=100, orient='vertical'), visualmap_opts=opts.VisualMapOpts(is_show=False, max_=6e4, min_=3000, dimension=0, range_color=['#f5d69f', '#f5898b', '#ef5055']), legend_opts=opts.LegendOpts(is_show=False), xaxis_opts=opts.AxisOpts(is_show=False,), yaxis_opts=opts.AxisOpts(axistick_opts=opts.AxisTickOpts(is_show=False), axisline_opts=opts.AxisLineOpts(is_show=False))) .set_series_opts(label_opts=opts.LabelOpts(is_show=True, position='right', font_style='italic'), itemstyle_opts={"normal": { "barBorderRadius": [30, 30, 30, 30], 'shadowBlur': 10, 'shadowColor': 'rgba(120, 36, 50, 0.5)', 'shadowOffsetY': 5, } }).reversal_axis())bar.render_notebook()
Out[4]:
In [5]:
t_data = data.groupby(['circumference', 'cup'])['datetime'].count().reset_index()t_data.columns = ['circumference', 'cup', 'num']#t_data.num = round(t_data.num.div(t_data.num.sum(axis=0), axis=0) * 100, 1)data_pair = [ {"name": 'A', "label":{"show": True}, "children": []}, {"name": 'B', "label":{"show": True}, "children": []}, {"name": 'C', "label":{"show": True}, 'shadowBlur': 10, 'shadowColor': 'rgba(120, 36, 50, 0.5)', 'shadowOffsetY': 5, "children": []}, {"name": 'D', "label":{"show": False}, "children": []}, {"name": 'E', "label":{"show": False}, "children": []} ]for idx, row in t_data.iterrows(): t_dict = {"name": row.cup, "label":{"show": True}, "children": []} if row.num > 3000: child_data = {"name": '{}-{}'.format(row.circumference, row.cup), "value":row.num, "label":{"show": True}} else: child_data = {"name": '{}-{}'.format(row.circumference, row.cup), "value":row.num, "label":{"show": False}} if row.cup == "A": data_pair[0]['children'].append(child_data) elif row.cup == "B": data_pair[1]['children'].append(child_data) elif row.cup == "C": data_pair[2]['children'].append(child_data) elif row.cup == "D": data_pair[3]['children'].append(child_data) elif row.cup == "E": data_pair[4]['children'].append(child_data)
單看罩杯的話:B > A > C
細分到具體尺碼:75B > 80B > 75A > 70A
In [6]:
c = (Sunburst( init_opts=opts.InitOpts( theme='purple-passion', width="1000px", height="1000px")) .add( "", data_pair=data_pair, highlight_policy="ancestor", radius=[0, "100%"], sort_='null', levels=[ {}, { "r0": "20%", "r": "48%", "itemStyle": {"borderColor": 'rgb(220,220,220)', "borderWidth": 2} }, {"r0": "50%", "r": "80%", "label": {"align": "right"}, "itemStyle": {"borderColor": 'rgb(220,220,220)', "borderWidth": 1}} ], ) .set_global_opts( visualmap_opts=opts.VisualMapOpts(is_show=False, max_=90000, min_=3000, range_color=['#f5d69f', '#f5898b', '#ef5055']), title_opts=opts.TitleOpts(title="文 胸\n\n尺 碼 分 布", pos_left="center", pos_top="center", title_textstyle_opts=opts.TextStyleOpts(font_style='oblique', font_size=30),)) .set_series_opts(label_opts=opts.LabelOpts(font_size=18, formatter="{b}: {c}")))c.render_notebook()
Out[6]:
我們通過不同的胸圍來看看罩杯的比例:
下胸圍=70:A > B > C
下胸圍=75:B > A > C
下胸圍=80:B > A > C
下胸圍=85:B > C > A
下胸圍=90:C > B > A
下胸圍=95:C > B > D
In [7]:
grid = Grid(init_opts=opts.InitOpts(theme='purple-passion', width='1000px', height='1000px'))for idx, c in enumerate(['70', '75', '80', '85', '90', '95']): if idx % 2 == 0: x = 30 y = int(idx/2) * 30 + 20 else: x = 70 y = int(idx/2) * 30 + 20 pos_x = str(x)+'%' pos_y = str(y)+'%' pie = Pie(init_opts=opts.InitOpts()) pie.add( c, [[row.cup, row.num]for i, row in t_data[t_data.circumference==c].iterrows()], center=[pos_x, pos_y], radius=[70, 100], label_opts=opts.LabelOpts(formatter='{b}:aegqsqibtmh%'), ) pie.set_global_opts( title_opts=opts.TitleOpts(title="下胸圍={}".format(c), pos_top=str(y-1)+'%', pos_left=str(x-4)+'%', title_textstyle_opts=opts.TextStyleOpts(font_size=15)), legend_opts=opts.LegendOpts(is_show=True)) grid.add(pie,grid_opts=opts.GridOpts(pos_left='20%'))grid.render_notebook()
Out[7]:
最后我們來看看評論中經常說到的是什么詞語吧~
In [8]:
w_all = []for item in data.comment: w_l = jieba.lcut(item) w_all.extend(w_l)c = Counter(w_all)
In [10]:
gen_stylecloud(' '.join(w_all), size=1000, #max_words=1000, font_path='/home/kesci/work/font/simhei.ttf', #palette='palettable.tableau.TableauMedium_10', icon_name='fas fa-heartbeat', output_name='comment.png', custom_stopwords=['沒有','用戶','填寫','評論'] )Image(filename='comment.png')
Out[10]:
“如何用Pyecharts生成云詞”的內容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業相關的知識可以關注億速云網站,小編將為大家輸出更多高質量的實用文章!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。