LoginSignup
0
2

More than 5 years have passed since last update.

ファッションサイトの投稿の傾向を知る

Last updated at Posted at 2017-11-29

概要

前回の
ファッションサイトからファッション画像とラベルを取ってくる
からとってきたlabels.txtから傾向を知る

コード

fat.py
#!/usr/bin/python
# coding: UTF-8
import math
import numpy as np
import matplotlib.pyplot as plt
from collections import OrderedDict

search = "トップス"

dict = {}

with open('labels.txt',encoding="utf-8_sig") as f:
    line = f.readline()
    while (line) :
        line = line.strip()
        #print(not line.isalpha())
        try:
            int(line)
        except Exception as e:
            if line in dict.keys():
                dict[line] =dict[line] + 1
            else:
                dict[line]  = 1
        line = f.readline()

valist = []       
for y in c.values():
    valist.append(y)

c = OrderedDict(sorted(dict.items(), key=lambda x:x[1]))


pupu = []
for i in c.keys():
    pupu.append(i.split())

pan = []
num  =[]
for y in range(len(pupu)):
    if search in pupu[y][0]:
        pan.append(pupu[y][1])
        num.append(valist[y])
print (pan)
print (num)

x = range(len(pan))
y = num

plt.bar(x,y, align="center")
plt.xticks(x,pan,rotation=90)
plt.show()

結果

tops.png

補足

matplotlibを日本語表示にするためにIPAexフォントを使用しています

0
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
2