export-to-csv

write.table writes unwanted leading empty column to header when has rownames

混江龙づ霸主 提交于 2019-11-28 02:53:35
check this example: > a = matrix(1:9, nrow = 3, ncol = 3, dimnames = list(LETTERS[1:3], LETTERS[1:3])) > a A B C A 1 4 7 B 2 5 8 C 3 6 9 the table displays correctly. There are two different ways of writing it to file... write.csv(a, 'a.csv') which gives as expected: "","A","B","C" "A",1,4,7 "B",2,5,8 "C",3,6,9 and write.table(a, 'a.txt') which screws up "A" "B" "C" "A" 1 4 7 "B" 2 5 8 "C" 3 6 9 indeed, an empty tab is missing.... which is a pain in the butt for downstream things. Is this a bug or a feature? Is there a workaround? (other than write.table(cbind(rownames(a), a), 'a.txt', row

SQL query output to .csv

半世苍凉 提交于 2019-11-28 02:21:22
问题 I am running SQL query from python API and want to collect data in Structured(column-wise data under their header).CSV format. This is the code so far I have. sql = "SELECT id,author From researches WHERE id < 20 " cursor.execute(sql) data = cursor.fetchall() print (data) with open('metadata.csv', 'w', newline='') as f_handle: writer = csv.writer(f_handle) header = ['id', 'author'] writer.writerow(header) for row in data: writer.writerow(row) Now the data is being printed on the console but

printing a new line in a csv file cell

大憨熊 提交于 2019-11-28 00:46:21
I am generating an CSV file in php. I need to print the text in new line inside a cell(I can do this in excel using Ctrl + Enter or Alt + Enter ). For that I tried using '\n' , '\r' , but nothing helped. How can I achieve this? I am using yii extension ECSVExport to generate csv. I want an output like this: ID Value 1 A B 2 C 3 E FF G 4 X Try this "\n" inside double quote Use "\n" inside the cell value (wrapped in " ) and "\r\n" for your end-of-record marker. If your cell entry include multiple lines, then you must enclose it in " $fh = fopen('test1.csv', 'w+'); fwrite($fh, "sep=\t" . "\r\n");

My csv export displaying html, how to get rid of?

主宰稳场 提交于 2019-11-27 22:43:16
问题 I've seen this asked before and I am having trouble getting this to work properly after trying a number of solutions. The problem is I can't get my data to export into a csv format properly. Before I added my ob_end_clean it would export out to a csv with html, now it doesn't give me a csv, just text. Here is my code on the file that is being required. if (isset($_POST["hidden"])) { $list = array ( array('aaa', 'bbb', 'ccc', 'dddd'), array('123', '456', '789'), array('"aaa"', '"bbb"') ); $fp

Export UTF-8 BOM to .csv in R

北慕城南 提交于 2019-11-27 20:52:30
I am reading a file through RJDBC from a MySQL database and it correctly displays all letters in R (e.g., נווה שאנן). However, even when exporting it using write.csv and fileEncoding="UTF-8" the output looks like <U+0436>.<U+043A>. <U+041B><U+043E><U+0437><U+0435><U+043D><U+0435><U+0446> (in this case this is not the string above but a Bulgarian one) for Bulgarian, Hebrew, Chinese and so on. Other special characters like ã,ç etc work fine. I suspect this is because of UTF-8 BOM but I did not find a solution on the net My OS is a German Windows7. edit: I tried con<-file("file.csv",encoding="UTF

export html table to csv

瘦欲@ 提交于 2019-11-27 19:16:40
I am trying to add a feature of csv download option in my website. It should convert the html table present in the website in to csv content and make it downloadable. Ive been searching through internet for a good plugin and found some usefule ones like http://www.dev-skills.com/export-html-table-to-csv-file/ But it uses php script to do the download part. I was wondering if there is a pure javascript library available to do this feature using server side softwares like node.js without the use of php?? melancia Using just jQuery , vanilla Javascript , and the table2CSV library: export-to-html

My csv export displaying html, how to get rid of?

五迷三道 提交于 2019-11-27 19:06:10
问题 I've seen this asked before and I am having trouble getting this to work properly after trying a number of solutions. The problem is I can't get my data to export into a csv format properly. Before I added my ob_end_clean it would export out to a csv with html, now it doesn't give me a csv, just text. Here is my code on the file that is being required. if (isset($_POST["hidden"])) { $list = array ( array('aaa', 'bbb', 'ccc', 'dddd'), array('123', '456', '789'), array('"aaa"', '"bbb"') ); $fp

Java append new column to csv file

不想你离开。 提交于 2019-11-27 17:03:24
问题 I want to calculate some column data and write it to csv file as column. Then after calculating other column of data I want to append it to same file but as new column. Here is what I did: try { FileWriter writer = new FileWriter(OUT_FILE_PATH, true); for (int i=0; i<data.size(); i++) { writer.append(String.valueOf(data.get(i))); writer.append(","); writer.append("\n"); } writer.flush(); writer.close(); } catch (Exception e) {} Result - It appends the new column below the first column, so I

Export csv file from scrapy (not via command line)

↘锁芯ラ 提交于 2019-11-27 14:37:46
问题 I successfully tried to export my items into a csv file from the command line like: scrapy crawl spiderName -o filename.csv My question is: What is the easiest solution to do the same in the code? I need this as i extract the filename from another file. End scenario should be, that i call scrapy crawl spiderName and it writes the items into filename.csv 回答1: Why not use an item pipeline? WriteToCsv.py import csv from YOUR_PROJECT_NAME_HERE import settings def write_to_csv(item): writer = csv

how to export Core Data to CSV

倾然丶 夕夏残阳落幕 提交于 2019-11-27 12:51:56
问题 I will like to use CHCSVParser to export my Core data to CSV. I know how to get all the value from entity, but I don't know how to write to CSV. Can anybody teach me how to write to CSV with CHCSVParser ? // Test listing all Infos from the store NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init]; NSEntityDescription *entity = [NSEntityDescription entityForName:@"NoteLog" inManagedObjectContext:context]; [fetchRequest setEntity:entity]; NSArray *fetchedObjects = [context