90,418 questions
2450
votes
51
answers
3.4m
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?
1165
votes
10
answers
2.8m
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 ...
915
votes
20
answers
1.5m
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,...
827
votes
13
answers
1.4m
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?
811
votes
21
answers
1.3m
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?
780
votes
6
answers
910k
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 ...
742
votes
12
answers
931k
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 ...
715
votes
51
answers
2.3m
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 ...
653
votes
34
answers
717k
views
Is it possible to force Excel recognize UTF-8 CSV files automatically? [closed]
I'm developing a part of an application that's responsible for exporting some data into CSV files. The application always uses UTF-8 because of its multilingual nature at all levels. But opening such ...
639
votes
36
answers
664k
views
Stop Excel from automatically converting certain text values to dates
Does anyone happen to know if there is a token I can add to my csv for a certain field so Excel doesn't try to convert it to a date?
I'm trying to write a .csv file from my application and one of the ...
558
votes
10
answers
3.3m
views
Error "(unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape" [duplicate]
I'm trying to read a CSV file into Python (Spyder), but I keep getting an error. My code:
import csv
data = open("C:\Users\miche\Documents\school\jaar2\MIK\2.6\vektis_agb_zorgverlener")
...
516
votes
15
answers
588k
views
How to export table as CSV with headings on Postgresql?
I'm trying to export a PostgreSQL table with headings to a CSV file via command line, however I get it to export to CSV file, but without headings.
My code looks as follows:
COPY products_273 to '/...
479
votes
7
answers
585k
views
How to add pandas data to an existing csv file?
I want to know if it is possible to use the pandas to_csv() function to add a dataframe to an existing csv file. The csv file has the same structure as the loaded data.
433
votes
18
answers
446k
views
How to pretty-print / view tabular file (e.g., CSV) from the command line? [closed]
What are some command-line CSV viewers for Linux or OSX? I'm thinking of something like less but that spaces out the columns in a more readable way. (I'd be fine with opening it with OpenOffice Calc ...
411
votes
11
answers
519k
views
Response Content type as CSV
I need to send a CSV file in HTTP response. How can I set the output response as CSV format?
This is not working:
Response.ContentType = "application/CSV";
395
votes
12
answers
398k
views
Convert xlsx to csv in Linux with command line
I'm looking for a way to convert xlsx files to csv files on Linux.
I do not want to use PHP/Perl or anything like that since I'm looking at processing several millions of lines, so I need something ...
383
votes
10
answers
246k
views
_csv.Error: field larger than field limit (131072)
I have a script reading in a csv file with very huge fields:
# example from http://docs.python.org/3.3/library/csv.html?highlight=csv%20dictreader#examples
import csv
with open('some.csv', newline='')...
361
votes
20
answers
502k
views
Parsing CSV files in C#, with header
Is there a default/official/recommended way to parse CSV files in C#? I don't want to roll my own parser.
Also, I've seen instances of people using ODBC/OLE DB to read CSV via the Text driver, and a ...
348
votes
39
answers
570k
views
How can I read and parse CSV files in C++?
I need to load and use CSV file data in C++. At this point it can really just be a comma-delimited parser (ie don't worry about escaping new lines and commas). The main need is a line-by-line parser ...
339
votes
7
answers
365k
views
How to properly escape a double quote in CSV?
I have a line like this in my CSV:
"Samsung U600 24"","10000003409","1","10000003427"
Quote next to 24 is used to express inches, while the quote just next to that quote closes the field. I'm ...
331
votes
26
answers
996k
views
How can I convert JSON to CSV?
I have a JSON file I want to convert to a CSV file. How can I do this with Python?
I tried:
import json
import csv
f = open('data.json')
data = json.load(f)
f.close()
f = open('data.csv')
csv_file = ...
322
votes
13
answers
512k
views
How to get rid of "Unnamed: 0" column in a pandas DataFrame read in from CSV file?
I have a situation wherein sometimes when I read a csv from df I get an unwanted index-like column named unnamed:0.
file.csv
,A,B,C
0,1,2,3
1,4,5,6
2,7,8,9
The CSV is read with this:
pd.read_csv('...
296
votes
7
answers
895k
views
How to add header row to a pandas DataFrame
I am reading a csv file into pandas. This csv file consists of four columns and some rows, but does not have a header row, which I want to add. I have been trying the following:
Cov = pd.read_csv(&...
292
votes
15
answers
545k
views
How to parse CSV data?
Where could I find some JavaScript code to parse CSV data?
275
votes
16
answers
1.1m
views
Writing data into CSV file in C#
I am trying to write into a csv file row by row using C# language. Here is my function
string first = reader[0].ToString();
string second=image.ToString();
string csv = string.Format("{0},{1}\n", ...