headers = ['col1','col2','col3']
CSV.open(file_path, 'a+', {force_quotes: true}) do |csv|
csv << headers if csv.count.eql? 0 # csv.count method gives number of lines in file if zero insert headers
end
headers = CSV.open('file.csv', 'r') { |csv| csv.first }
Code Example |
---|
Ruby :: rails column datetime |
Ruby :: ruby open file and append |
Ruby :: ruby each |
Ruby :: What does inject in ruby do |
Ruby :: require multiple files ruby |
Ruby :: font awesome rails |
Ruby :: validations rails integer suprior to 0 |
Ruby :: random number rails |
Ruby :: ffi gem error mac |
Ruby :: ruby random number between |
Ruby :: rails increment counter model |
Ruby :: rails array pop first n elements |
Ruby :: ruby sort method |
Ruby :: user.destroy all except one rails |
Ruby :: initialize hash with 0 value ruby |
Ruby :: EOFError: end of file reached |
Ruby :: symbols used in hashes |
Ruby :: devise valid password |
Ruby :: common functions in rails |
Ruby :: rails migration error |
Ruby :: ruby file copy |
Ruby :: ruby puts format |
Ruby :: rails revert migration |
R :: r remove leading and trailing whitespace |
R :: read csv file in r |
R :: how to title plot in r |
R :: custom function in r |
R :: how to read multiple csv files from a directory in r |
R :: convert index to column r |
R :: for R |