Questions tagged [csv]

Comma-Separated Values or Character-Separated Values (CSV) is a common "flat file database" (or spreadsheet-style) format for storing tabular data in plain text, with fields separated by a special character (comma, tab, etc). Rows are typically denoted by newline characters. Use for any delimited file formats, including tab delimited (TSV)

CSV is a file format involving a plain text file with information separated by delimiters with the purpose of storing data in a table-structured format. CSV (comma separated values) files traditionally and most commonly use a comma delimiter (hence the name), but other characters can be used, such as semi-colons, tabs, pipe symbols (|), etc.

The MIME type for CSV files is text/csv.

Information is often stored in CSV format to make it easy to transfer tables of data between applications. Each row of a table is represented as a list of plain text (human-readable) values with a delimiter character between each discrete piece of data. Values may be enclosed in quotes, which is required if they contain the delimiter as a value. The first row of data often contains headers of table's columns, which describe the meaning of the data in each column.

Example

Tabular format

Time Temperature Humidity Description
08:00 70 35 Sunny and Clear
11:45 94 90 Hazy, Hot, and Humid
14:30 18 Freezing
16:00 -200 "Unliveable"

CSV format

Time,Temperature,Humidity,Description
08:00,70,35,Sunny and Clear
11:45,94,90,"Hazy, Hot, and Humid"
14:30,18,,Freezing
16:00,-200,,""Unliveable""

In this example, the first row of CSV data serves as the "header", which describes the corresponding data below it. There is no inherent way to describe within a CSV file whether the first row is a header row or not. Each successive line of the CSV file should neatly fit into the same field as the first line.

Note:

  • Empty fields (fields with no available data, such as the third field in the last line) are place-held with commas so that the fields that follow may be correctly placed.
  • Since the comma is the delimiter for fields, the commas in the Description field of the second line must be quoted (to prevent them from being interpreted as field delimiters). Wrapping the entire field in double quotes (") is the default method for protecting the delimiter character inside a field.
  • Since the double-quote is the delimiter quote character, double-quotes in the data, as in "Unliveable" on the fourth line, must also be protected. Doubling-up the double-quote is the default method for protecting the quote character inside a field.

Questions tagged are expected to relate to programming in some way, for example, parsing/importing CSV files or creating them programmatically.

Related links:

89606 questions
13
votes
2 answers

Export data from Google App Engine to csv

This old answer points to a link on Google App Engine documentation, but that link is now about backup your GAE data, not downloading it. So how to download all the data into a csv? The data is small, i.e < 1 GB
Heisenberg
  • 8,386
  • 12
  • 53
  • 102
13
votes
2 answers

How to generate a file without saving it to disk in python?

I'm using Python 2.7 and Django 1.7. I have a method in my admin interface that generates some kind of a csv file. def generate_csv(args): ... #some code that generates a dictionary to be written as csv .... # this creates a…
Saša Kalaba
  • 4,241
  • 6
  • 29
  • 52
13
votes
1 answer

_csv.reader' object is not subscriptable

I have a problem with the csv module in python. This is the code I've written to parse my csv def parse(data): data_delim = data.split("\n") data_list = csv.reader(data_delim) return data_list The problem I am encountering is the…
user3983157
13
votes
8 answers

Reading/writing CSV/tab delimited files in c#

I need to read from a CSV/Tab delimited file and write to such a file as well from .net. The difficulty is that I don't know the structure of each file and need to write the cvs/tab file to a datatable, which the FileHelpers library doesn't seem to…
Tim Almond
  • 12,088
  • 10
  • 40
  • 50
13
votes
1 answer

How do I add a constant column value during data transfer from CSV to SQL?

I am reading in CSV file and translating it to an SQL Table. The kicker is that one of the columns in the table is of data type ID that needs to be set to a constant (in this case 2). I am not sure how to do this.
Craig
  • 11,614
  • 13
  • 44
  • 62
13
votes
2 answers

csv.reader() is separating values by individual character

I have the following code trying to iterate over some items: Here is the input (Single line) operation,sku,item_name,upc,ean,brand_name filename=open("WebstoreItemTemplate.csv").read() template=csv.reader(filename,delimiter=',') for row in…
Ben C Wang
  • 617
  • 10
  • 19
13
votes
3 answers

Read csv with dd.mm.yyyy in Python and Pandas

I am reading a csv file with German date format. Seems like it worked ok in this post: Picking dates from an imported CSV with pandas/python However, it seems like in my case the date is not recognized as such. I could not find any wrong string in…
RogerWilco77
  • 319
  • 1
  • 3
  • 13
13
votes
4 answers

Return a csv encoded in UTF-8 with BOM from django

I'm trying to output a CSV file that the user could open with excel. I've encoded all string in UTF-8 but when I opened the file with excel I see jibrish. Only after converting the file to UTF-8 with BOM (using notepad++ on windows) I was able to…
haki
  • 9,389
  • 15
  • 62
  • 110
13
votes
1 answer

How to generate @timestamp in logstash by combining two fields / columns of input csv

We have data that is coming from external sources as below in csv file: orderid,OrderDate,BusinessMinute,Quantity,Price 31874,01-01-2013,00:06,2,17.9 The data has date in one column and time in another column - I need to generate a time-stamp by…
Gopalakrishna Palem
  • 1,705
  • 1
  • 20
  • 34
13
votes
5 answers

convert CSV lines into Javascript objects

I have a simple csv file people.csv: fname, lname, uid, phone, address John, Doe, 1, 444-555-6666, 34 dead rd Jane, Doe, 2, 555-444-7777, 24 dead rd Jimmy, James, 3, 111-222-3333, 60 alive way What I want to do it get each line of the CSV, convert…
GGMU
  • 165
  • 1
  • 2
  • 13
13
votes
3 answers

Skip comment line in csv file using R

I have a csv file which looks like this- #this is a dataset #this contains rows and columns ID value1 value2 value3 AA 5 6 5 BB 8 2 9 CC 3 5 2 I want read the csv…
jessy
  • 191
  • 2
  • 8
13
votes
6 answers

Ignore first line on csv parse Rails

I am using the code from this tutorial to parse a CSV file and add the contents to a database table. How would I ignore the first line of the CSV file? The controller code is below: def csv_import …
Jack
  • 3,878
  • 15
  • 42
  • 72
13
votes
4 answers

Define Excel's column width with R

The final product is an Excel CSV spreadsheet which has more than 250 columns. I was wondering if there was a way to determine the column width in Excel from R? I am using write.csv2, which produces column width in excel all equal to 8,43.…
Kvasir EnDevenir
  • 907
  • 1
  • 10
  • 25
13
votes
3 answers

How to validate CSV in C#?

Is there a built-in method in .NET that validates csv files/strings? I would prefer something like this online csv validator but in C#. I have done some research but all I have found are examples of people writing the code themselves (examples were…
user3772119
  • 484
  • 3
  • 7
  • 16
13
votes
2 answers

Export HTML table to csv in google chrome browser

i have following function by using this i am exporting my html to Csv file. few days/months ago it was working fine in google chrome browser (still its working fine in FF). now suddenly it stops working to convert data in to csv format. when i am…
Kalpit
  • 4,906
  • 4
  • 25
  • 43