Skip to main content
How are we doing? Please help us improve Stack Overflow. Take our short survey

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)

2424 votes
48 answers
3.3m views

How to concatenate text from multiple rows into a single text string in SQL Server

Consider a database table holding names, with three rows: Peter Paul Mary Is there an easy way to turn this into a single string of Peter, Paul, Mary?
JohnnyM's user avatar
  • 29.3k
1437 votes
40 answers
1.7m views

How can I output MySQL query results in CSV format?

Is there an easy way to run a MySQL query from the Linux command line and output the results in CSV format? Here's what I'm doing now: mysql -u uid -ppwd -D dbname << EOQ | sed -e 's/ /,/...
MCS's user avatar
  • 22.4k
1129 votes
10 answers
2.6m views

Writing a pandas DataFrame to CSV file

I have a dataframe in pandas which I would like to write to a CSV file. I am doing this using: df.to_csv('out.csv') And getting the following error: UnicodeEncodeError: 'ascii' codec can't encode ...
user7289's user avatar
  • 33.7k
1127 votes
21 answers
955k views

Save PL/pgSQL output from PostgreSQL to a CSV file

What is the easiest way to save PL/pgSQL output from a PostgreSQL database to a CSV file? I'm using PostgreSQL 8.4 with pgAdmin III and PSQL plugin where I run queries from.
Hoff's user avatar
  • 39.4k
906 votes
20 answers
1.4m views

How can I convert a comma-separated string to an array?

I have a comma-separated string that I want to convert into an array, so I can loop through it. Is there anything built-in to do this? For example, I have this string var str = "January,February,...
Blankman's user avatar
  • 265k
834 votes
8 answers
1.2m views

Remove trailing delimiting character from a delimited string

What is fastest way to remove the last character from a string? I have a string like a,b,c,d,e, I would like to remove the last ',' and get the remaining string back: OUTPUT: a,b,c,d,e What is ...
I-M-JM's user avatar
  • 15.9k
809 votes
13 answers
1.3m views

Dump a NumPy array into a csv file

How do I dump a 2D NumPy array into a csv file in a human-readable format?
Dexter's user avatar
  • 11.7k
798 votes
31 answers
1.0m views

How to export JavaScript array info to csv (on client side)?

I know there are lot of questions of this nature but I need to do this using JavaScript. I am using Dojo 1.8 and have all the attribute info in array, which looks like this: [["name1", "city_name1", ....
Sam007's user avatar
  • 8,667
797 votes
21 answers
1.2m views

How to import CSV file data into a PostgreSQL table

How can I write a stored procedure that imports data from a CSV file and populates the table?
vardhan's user avatar
  • 7,979
768 votes
20 answers
987k views

Import multiple CSV files into pandas and concatenate into one DataFrame

I would like to read several CSV files from a directory into pandas and concatenate them into one big DataFrame. I have not been able to figure it out though. Here is what I have so far: import glob ...
jonas's user avatar
  • 13.8k
750 votes
6 answers
841k views

How to avoid pandas creating an index in a saved csv

I am trying to save a csv to a folder after making some edits to the file. Every time I use pd.to_csv('C:/Path of file.csv') the csv file has a separate column of indexes. I want to avoid printing ...
Alexis's user avatar
  • 8,921
731 votes
11 answers
568k views

CSV file written with Python has blank lines between each row

import csv with open('thefile.csv', 'rb') as f: data = list(csv.reader(f)) import collections counter = collections.defaultdict(int) for row in data: counter[row[10]] += 1 with open(...
Alex Gordon's user avatar
  • 59.3k
730 votes
12 answers
888k views

HTML Input="file" Accept Attribute File Type (CSV)

I have a file upload object on my page: <input type="file" ID="fileSelect" /> with the following excel files on my desktop: file1.xlsx file1.xls file.csv I want the file ...
Dom's user avatar
  • 40.1k
713 votes
27 answers
1.1m views

UnicodeDecodeError when reading CSV file in Pandas

I'm running a program which is processing 30,000 similar files. A random number of them are stopping and producing this error... File "C:\Importer\src\dfman\importer.py", line 26, in ...
TravisVOX's user avatar
  • 21.4k
699 votes
50 answers
2.1m views

pandas.parser.CParserError: Error tokenizing data

I'm trying to use pandas to manipulate a .csv file but I get this error: pandas.parser.CParserError: Error tokenizing data. C error: Expected 2 fields in line 3, saw 12 I have tried to read the ...
abuteau's user avatar
  • 7,321

15 30 50 per page
1
2 3 4 5
6033