export-to-csv

How to export a table dataframe in PySpark to csv?

三世轮回 提交于 2019-11-27 00:40:01
I am using Spark 1.3.1 (PySpark) and I have generated a table using a SQL query. I now have an object that is a DataFrame . I want to export this DataFrame object (I have called it "table") to a csv file so I can manipulate it and plot the columns. How do I export the DataFrame "table" to a csv file? Thanks! If data frame fits in a driver memory and you want to save to local files system you can convert Spark DataFrame to local Pandas DataFrame using toPandas method and then simply use to_csv : df.toPandas().to_csv('mycsv.csv') Otherwise you can use spark-csv : Spark 1.3 df.save('mycsv.csv',

How to export dataGridView data Instantly to Excel on button click?

余生长醉 提交于 2019-11-27 00:20:41
I have 10k rows and 15 column in my data grid view. I want to export this data to an excel sheet o button click. I have already tried with the below code. private void btExport_Click(object sender, EventArgs e) { Microsoft.Office.Interop.Excel._Application app = new Microsoft.Office.Interop.Excel.Application(); Microsoft.Office.Interop.Excel._Workbook workbook = app.Workbooks.Add(Type.Missing); Microsoft.Office.Interop.Excel._Worksheet worksheet = null; app.Visible = true; worksheet = workbook.Sheets["Sheet1"]; worksheet = workbook.ActiveSheet; for(int i=1;i<dataGridView1.Columns.Count+1;i++)

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

三世轮回 提交于 2019-11-26 23:56:30
问题 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

Export UTF-8 BOM to .csv in R

好久不见. 提交于 2019-11-26 22:59:19
问题 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

Export-CSV exports length but not name

这一生的挚爱 提交于 2019-11-26 22:50:57
I have this code that I am running from powershell. When I run it without the export-csv i get all the folder names on the screen. dir | select -expand fullname | % { ($_ -split '\')[7] But if I add | export-csv c:\test.txt then I see following in the file not the folder name I expected just like I see it on the screen. #TYPE System.String "Length" "13" "18" "20" "22" "29" "21" "24" "11" "17" "20" "20" mjolinor Export-Csv exports a table of object properties and their values. Since your script is producing string objects, and the only property they have is length, that's what you got. If you

Exporting a PostgreSQL query to a csv file using Python

杀马特。学长 韩版系。学妹 提交于 2019-11-26 21:51:44
问题 I need to export some rows from a table in a PostgreSQL database to a .csv file using a Python script: #!/usr/bin/python # -*- coding: utf-8 -*- import sys, psycopg2 ... conn = psycopg2.connect("dbname=dbname user=user password=password") cur = conn.cursor() sql = "\copy (SELECT * FROM table WHERE month=6) TO '/mnt/results/month/table.csv' WITH CSV DELIMITER ';';" cur.execute(sql) cur.close() ... But when I run the script I get this: Syntax error at or near «\» LINE 1: \copy (SELECT * FROM

export html table to csv

北战南征 提交于 2019-11-26 19:48:38
问题 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

How to export data from Spark SQL to CSV

江枫思渺然 提交于 2019-11-26 19:18:43
问题 This command works with HiveQL: insert overwrite directory '/data/home.csv' select * from testtable; But with Spark SQL I'm getting an error with an org.apache.spark.sql.hive.HiveQl stack trace: java.lang.RuntimeException: Unsupported language features in query: insert overwrite directory '/data/home.csv' select * from testtable Please guide me to write export to CSV feature in Spark SQL. 回答1: You can use below statement to write the contents of dataframe in CSV format df.write.csv("/data

xls to csv converter

◇◆丶佛笑我妖孽 提交于 2019-11-26 18:26:08
I am using win32.client in python for converting my .xlsx and .xls file into a .csv. When I execute this code it's giving an error. My code is: def convertXLS2CSV(aFile): '''converts a MS Excel file to csv w/ the same name in the same directory''' print "------ beginning to convert XLS to CSV ------" try: import win32com.client, os from win32com.client import constants as c excel = win32com.client.Dispatch('Excel.Application') fileDir, fileName = os.path.split(aFile) nameOnly = os.path.splitext(fileName) newName = nameOnly[0] + ".csv" outCSV = os.path.join(fileDir, newName) workbook = excel

How do I export html table data as .csv file?

时光毁灭记忆、已成空白 提交于 2019-11-26 17:58:25
问题 I have a table of data in an html table on a website and need to know how to export that data as .csv file. How would this be done? 回答1: For exporting html to csv try following this example. More details and examples are available at the author's website . Create a html2csv.js file and put the following code in it. jQuery.fn.table2CSV = function(options) { var options = jQuery.extend({ separator: ',', header: [], delivery: 'popup' // popup, value }, options); var csvData = []; var headerArr =