How to use mongoimport to import CSV files?

Your example worked for me with MongoDB 1.6.3 and 1.7.3. Example below was for 1.7.3. Are you using an older version of MongoDB? $ cat > locations.csv Name,Address,City,State,ZIP Jane Doe,123 Main St,Whereverville,CA,90210 John Doe,555 Broadway Ave,New York,NY,10010 ctrl-d $ mongoimport -d mydb -c things –type csv –file locations.csv –headerline connected to: 127.0.0.1 imported 3 objects … Read more

Extract specific columns from delimited file using Awk

I don’t know if it’s possible to do ranges in awk. You could do a for loop, but you would have to add handling to filter out the columns you don’t want. It’s probably easier to do this: awk -F, ‘{OFS=”,”;print $1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$20,$21,$22,$23,$24,$25,$30,$33}’ infile.csv > outfile.csv something else to consider – and this faster and more … Read more

pandas DataFrame output end of csv

You can append using to_csv by passing a file which is open in append mode: with open(file_name, ‘a’) as f: df.to_csv(f, header=False) Use header=None, so as not to append the column names. In fact, pandas has a wrapper to do this in to_csv using the mode argument (see Joe’s answer): df.to_csv(f, mode=”a”, header=False)

Why am I getting mime-type of .csv file as “application/octet-stream”?

In times like these, the official HTTP specification is always helpful. From RFC 2616 7.2.1 (my emphasis added): Any HTTP/1.1 message containing an entity-body SHOULD include a Content-Type header field defining the media type of that body. If and only if the media type is not given by a Content-Type field, the recipient MAY attempt … Read more

Converting JSON object to CSV format in JavaScript

Probably more elegant and the simplest solution function convertToCSV(arr) { const array = [Object.keys(arr[0])].concat(arr) return array.map(it => { return Object.values(it).toString() }).join(‘\n’) } console.log( convertToCSV( [ { id: 1, name: ‘Foo’, timestamp: new Date() }, { id: 2, name: ‘Bar’, timestamp: new Date() }, { id: 3, name: ‘Baz’, timestamp: new Date() } ] ) )