[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
5
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Rubyで前処理。Pixivタグ検索結果に対しタグカウントを実行。

Last updated at Posted at 2014-03-26

#概要
前回記事で取得したPixiv検索結果CSVからタグを抽出し、タグの出現数を降順に列挙する。

#コード

TagCount.rb
# coding: UTF-8

require 'csv'

h = {}
h.default = 0
CSV.foreach('INPUT.csv', encoding: "UTF-8") do |row|
	row[13].split(' ').each do |item|
		h[item] += 1
	end
end

CSV.open("OUTPUT.csv", "wb") do |csv|
	h.sort_by{|key, value| -value}.each do |set|
		csv << [set[0], set[1]]
	end
end

puts 'end!'

#出力結果(サンプル)
男の娘,35
こんな可愛い子が女の子のはずがない,10
だが男だ,10
オリジナル1000users入り,9
女装男子,8
オリジナル,8
女装,8
(以下略)

5
6
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
5
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?