csv

Upload CSV stream from Ruby to S3

这一生的挚爱 提交于 2020-07-05 06:40:30
问题 I am dealing with potentially huge CSV files which I want to export from my Rails app, and since it runs on Heroku, my idea was to stream these CSV files directly to S3 when generating them. Now, I have an issue, in that Aws::S3 expects a file in order to be able to perform an upload, while in my Rails app I would like to do something like: S3.bucket('my-bucket').object('my-csv') << %w(this is one line) How can I achieve this? 回答1: You can use s3 multipart upload that allows upload by

CsvHelper wrap all valus with quotes

假装没事ソ 提交于 2020-07-03 03:20:10
问题 I am using CsvHelper I need to wrap all values with quotes. Is that possible? Data = is a List using (StreamWriter textWriter = new StreamWriter(path)) { textWriter.BaseStream.Write(p, 0, p.Length); // var dt = new DataTable(); var csv = new CsvWriter(textWriter); csv.WriteRecords(Data); textWriter.Flush(); textWriter.Close(); } Thanks 回答1: There is a config value called ShouldQuote where you can determine on a field level if it should be quoted. void Main() { var records = new List<Foo> {

How do I print only the first 10 lines from a csv file using Python?

与世无争的帅哥 提交于 2020-07-02 09:38:58
问题 I'm new to Python and I'm wanting to print only the first 10 lines of a huge csv file. Here's my code so far that prints all of the lines in the csv file import csv with open('titanic.csv') as csvfile: reader = csv.DictReader(csvfile) for row in reader: print(row['survived'], row['pclass'], row['name'], row['sex'], row['age']) 回答1: You could just break after 10 lines. import csv with open('titanic.csv') as csvfile: reader = csv.DictReader(csvfile) for i,row in enumerate(reader): print(row[

How do I print only the first 10 lines from a csv file using Python?

℡╲_俬逩灬. 提交于 2020-07-02 09:37:34
问题 I'm new to Python and I'm wanting to print only the first 10 lines of a huge csv file. Here's my code so far that prints all of the lines in the csv file import csv with open('titanic.csv') as csvfile: reader = csv.DictReader(csvfile) for row in reader: print(row['survived'], row['pclass'], row['name'], row['sex'], row['age']) 回答1: You could just break after 10 lines. import csv with open('titanic.csv') as csvfile: reader = csv.DictReader(csvfile) for i,row in enumerate(reader): print(row[

failed to read inch symbol in pandas read_csv

て烟熏妆下的殇ゞ 提交于 2020-06-29 12:53:09
问题 I have csv with below details Name,Desc,Year,Location Jhon,12" Main Third ,2012,GR Lew,"291" Line (12,596,3)",2012,GR ,All, 1992,FR ... It is very long file. i just showed problematic lines.I am confused how can i read it in Pandas data frame, I tried quotechar, quoting, sep like attribute of pandas read_csv . Still no success. I have no control on how csv is being designed. 回答1: You can do something like this. Try if this works for you: import pandas as pd import re l1=[] with open('/home

failed to read inch symbol in pandas read_csv

心不动则不痛 提交于 2020-06-29 12:52:06
问题 I have csv with below details Name,Desc,Year,Location Jhon,12" Main Third ,2012,GR Lew,"291" Line (12,596,3)",2012,GR ,All, 1992,FR ... It is very long file. i just showed problematic lines.I am confused how can i read it in Pandas data frame, I tried quotechar, quoting, sep like attribute of pandas read_csv . Still no success. I have no control on how csv is being designed. 回答1: You can do something like this. Try if this works for you: import pandas as pd import re l1=[] with open('/home

python script in cron not reading a CSV unless it creates the CSV itself

北城以北 提交于 2020-06-29 06:44:19
问题 I have the following script. It works when I run it in command line, and it works when I run it in cron. The variable 'apath' is the absolute path of the file. cat=['a','a','a','a','a','b','b','b','b','b'] val=[1,2,3,4,5,6,7,8,9,10] columns=['cat','val'] data=[cat,val] dict={key:value for key,value in zip(columns,data)} statedata_raw=pd.DataFrame(data=dict) statedata_raw.to_csv(apath+'state_data.csv',index=False) statedata_raw2=pd.read_csv(apath+'state_data.csv') statedata_raw2.to_csv(apath+

python script in cron not reading a CSV unless it creates the CSV itself

三世轮回 提交于 2020-06-29 06:44:11
问题 I have the following script. It works when I run it in command line, and it works when I run it in cron. The variable 'apath' is the absolute path of the file. cat=['a','a','a','a','a','b','b','b','b','b'] val=[1,2,3,4,5,6,7,8,9,10] columns=['cat','val'] data=[cat,val] dict={key:value for key,value in zip(columns,data)} statedata_raw=pd.DataFrame(data=dict) statedata_raw.to_csv(apath+'state_data.csv',index=False) statedata_raw2=pd.read_csv(apath+'state_data.csv') statedata_raw2.to_csv(apath+

getline to read in a string that has both white spaces and is comma seperated

心已入冬 提交于 2020-06-29 06:32:05
问题 Okay, so i have a file that has a string like so: 10/11/12 12:30 PM,67.9,78,98 ... ... I want to separate it like so 10/11/12 12:30 PM 67.9 I know you use getline to separate the comma separated stuff: getline(infile, my_string, ',') but I also know that doing this to get the date: getline(infile, my_string, ' ') would read in the spaces into my_string so is there any other way to go about this? Also, what would I need to do to skip over the last 2 (78,98) and go to the next line? Would just

How to read data from .mat file and export to CSV in python?

我只是一个虾纸丫 提交于 2020-06-29 04:12:31
问题 I know there are many answers but none of them solved my problem. I have a .mat file and i want to export it's data to Csv. The code that i tried: import h5py arrays={} f=h5py.File('datafile.mat') for k,v in f.items(): arrays[k]=np.array(v) Which got me output in dictionary {'#refs#': array(['0', '00', '00b', ..., 'zzj', 'zzk', 'zzl'], dtype='<U3'), 'MasterOperations': array(['Code', 'ID', 'Label'], dtype='<U5'), 'Operations': array(['CodeString', 'ID', 'Keywords', 'MasterID', 'Name'], dtype=