Created
May 22, 2019 03:35
-
-
Save takkii/4ec660bc3f5f7b76cc805dff665b3ab3 to your computer and use it in GitHub Desktop.
CSVのサンプル
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20190516 | 1111 | |
---|---|---|
20170530 | 2222 | |
20190420 | 3333 | |
20180520 | 4444 | |
20190515 | 5555 | |
20170213 | 1111 | |
20190422 | 6666 |
20190516,1111,20190515,5555,20190422,6666,20190420,3333,20180520,4444,20170530,2222
整形前。出力結果←試行錯誤中、試作品。
整形前を処理する機能もあればいいのだろうが、エディタの機能で済むよな。
それさえもしてしまいたかったのでしました。
書き出しているから、多少の手合わせはエディタでプログラムを書くまでもない。ぐぅ。の根も出ない。
邪念がなくなるとできるんだよな、
sample.csvを読み込み(元データ、完成形)
require 'csv'
CSV.open("write-file.csv", "w") do |test|
row = CSV.read("sample.csv")
are = row.to_h.sort.reverse
are.slice!(6)
are.join(',')
are.each_with_index do |a|
puts "#{a.to_csv}"
test << a
end
end
write-file.csvに書き込み(加工後、完成形)
20190516,1111
20190515,5555
20190422,6666
20190420,3333
20180520,4444
20170530,2222
これでRubyで実装できることが証明されました。使おうぜ、CSV加工にRubyを。
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
write-file.csvに書き込み(加工後、試作品)
多少、エディタの機能で整形した結果。