csv

Python pandas - merge csv files in directory into one

时间秒杀一切 提交于 2021-01-28 12:17:22
问题 I have a directory with csv files: frames/df1.csv df2.csv frames are structured like this: df1.csv artist track plays 1 Pearl Jam Jeremy 456 2 The Rolling Stones Heart of Stone 546 df2.csv artist track likes 3 Pearl Jam Jeremy 5673 9 The Rolling Stones Heart of Stone 3456 and I would like to merge all frames into one, ending up with: artist track plays likes 0 Pearl Jam Jeremy 456 5673 1 The Rolling Stones Heart of Stone 546 3456 I've tried: path = 'frames' all_files = glob.glob(path + "/*

Convert to csv from json in powershell

我是研究僧i 提交于 2021-01-28 12:00:57
问题 this is my csv: "name,data Play,http://{gho}.domain.com/ BDomain,domain.com Charts,2 Compress,0 CompressJ,0" | ConvertFrom-Csv | ConvertTo-Json Gives me: [ { "name": "Play", "data": "http://{gho}.domain.com/" }, { "name": "BDomain", "data": "domain.com" }, { "name": "Charts", "data": "2" }, { "name": "Compress", "data": "0" }, { "name": "CompressJ", "data": "0" } ] I would now like to get that csv back from my json, however the chains of | ConvertFrom-Json | ConvertTo-CSV are not working, and

Retrieve row number with supercsv

随声附和 提交于 2021-01-28 11:59:20
问题 Is there a way with the super-csv library to find out the row number of the file that will be processed? In other word, before i start to process my rows with a loop: while ((obj = csvBeanReader.read(obj.getClass(), csvModel.getNameMapping(), processors)) != null) { //Do some logic here... } Can i retrieve with some library class the number of row contained into the csv file? 回答1: No, in order to find out how many rows are in your CSV file, you'll have to read the whole file with Super CSV

How to export csv file with shift-jis encoding in laravel?

偶尔善良 提交于 2021-01-28 11:11:02
问题 I am using laravel-excel to export csv file. To export, the code is like below, return Excel::download(new Export(results,$header), "test.csv"); And the Export.php file is like, namespace App\AllClass; use Maatwebsite\Excel\Concerns\FromCollection; use Maatwebsite\Excel\Concerns\Exportable; use Maatwebsite\Excel\Concerns\WithHeadings; class Export implements FromCollection,WithHeadings { private $myArray; private $header; public function __construct($myArray,$header){ $this->myArray =

group objects by a field and sum another, then produce a CSV report

不羁岁月 提交于 2021-01-28 10:56:01
问题 How can I create a csv from this json? I have: [ { "name": "John", "cash": 5 }, { "name": "Anna", "cash": 4 }, { "name": "Anna", "cash": 3 }, { "name": "John", "cash": 8 } ] I need group by name and sum the cash and send the result a .csv like: John,13 Anna,7 Thanks! 回答1: JQ has group_by as a builtin, use that and do map(.cash) | add to sum cash values for each group. group_by(.name)[] | [.[0].name, (map(.cash) | add)] | @csv Online demo 来源: https://stackoverflow.com/questions/61953604/group

How to read a stream with comma separated values in C++?

倾然丶 夕夏残阳落幕 提交于 2021-01-28 09:49:11
问题 I would like to emphasize on a fundamental question below: Assume you have a CSV file and fill cells with Input Headers The code should read this from .csv file and write the results into .csv file. It is nice to also code output total number of cases, plus average of cases. Here is a taken sample form SO and I would like to see how this can be efficiently adopted to complete this basic example. void create() { // file pointer fstream fout; // opens an existing csv file or creates a new file.

Python: Issue with delimiter inside column data

冷暖自知 提交于 2021-01-28 09:38:38
问题 This is no duplicate of another question, as I do not want to drop the rows. The accepted answer in the aforementioned post is very different from this one, and not aimed at maintaining all the data. Problem: Delimiter inside column data from badly formatted csv-file Tried solutions: csv module , shlex, StringIO (no working solution on SO) Example data Delimiters are inside the third data field, somewhere enclosed by (multiple) double-quotes: 08884624;6/4/2016;Network routing 21,5\"\" 4

Using Golang to read csv, reorder columns then write result to a new csv with Concurrency

别等时光非礼了梦想. 提交于 2021-01-28 09:18:20
问题 Here's my starting point. It is a Golang script to read in a csv with 3 columns, re-order the columns and write the result to a new csv file. package main import ( "fmt" "encoding/csv" "io" "os" "math/rand" "time" ) func main(){ start_time := time.Now() // Loading csv file rFile, err := os.Open("data/small.csv") //3 columns if err != nil { fmt.Println("Error:", err) return } defer rFile.Close() // Creating csv reader reader := csv.NewReader(rFile) lines, err := reader.ReadAll() if err == io

How to automatically change the format or encode the excel cell value while writing it to CSV file

北城余情 提交于 2021-01-28 09:01:31
问题 My script is breaking when excel cell has double quotes in their value and quotes. I had to explicitly write a function to handle commas in OUTFILE. Is there any way I can provide cell value and automatically it can be encoded to CSV format. example- cell->value - Student GOT 8 MARKS in math, 7 in Spanish Desired Correct CSV format-> "Student GOT 8 MARKS in math, 7 in Spanish". cell->value - Student GOT 8 MARKS in "math", 7 in "Spanish" Desired Correct CSV format-> "Student GOT 8 MARKS in "

Karate - Ability to execute tests on a specific set of data in a csv file

会有一股神秘感。 提交于 2021-01-28 08:10:21
问题 I am on a team, presenting the advantages of Karate to move forward as the framework of choice for our API testing. However, I have come across a couple questions, in regards to data-driven testing. I have gone through the documentation, csv files and cannot find a solution for this question: Is Karate capable of executing tests on specific data sets (For instance, based on priority p0, p1) given in a csv file? Example "test.csv": |priority|data1| | p0 | 1 | | p0 | 2 | | p1 | 4 | | p1 | 6 | I