LoginSignup
2
1

More than 5 years have passed since last update.

CSVを読み込んでなにかやるときのテンプレ

Last updated at Posted at 2018-03-14

1,2ヶ月に1回くらいの頻度で書いている気がするのでメモ。
※下のコメントにあるライブラリ利用がオススメ↓

file_name = './hogehoge.csv'
file = File.open(file_name, 'r').read
rows = file.split("\n")

# ヘッダーを削除
rows.shift

rows.each do |row|
  ary = row.split(',')
  # do something
end
2
1
2

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
2
1