Posts

Showing posts with the label csv

how to use the binary mode for csv file in python 3.6?

how to use the binary mode for csv file in python 3.6? I have the following code : file_name="data.csv" temp_file=NamedTemporaryFile(delete=False) with open(file_name,"rb") as csvfile, temp_file: #b stands for binary reader=csv.DictReader(csvfile) fieldnames=['id','name', 'email', 'amount', 'sent'] writer=csv.DictWriter(temp_file, fieldnames=fieldnames) #writer.writeheader() print(temp_file.name) for row in reader: print(row) writer.writerow({ "id":row["id"], "name":row["name"], "email":row["email"], "amount":"1293.33", "sent":"" }) and the following error: _csv.Error: iterator should return strings, not bytes (did you open the file in text mode?) what should be done? ...

CSV Search AutoIT

Image
CSV Search AutoIT I have a CSV file that contains 4 columns, I want to search column 2 and change the corresponding data in column 4 using AutoIT: col 1 col 2 col 3 col 4 1 502 shop 25.00 2 106 house 50.00 3 307 boat 15.00 2 Answers 2 If the columns are separated by tabs then you could use StringSplit for that. $s1 = '1 502 shop 25.00' $s2 = '2 106 house 50.00' $s3 = '3 307 boat 15.00' For $i=1 To 3 $array = StringSplit(Eval('s' & $i), @TAB) ConsoleWrite('Column 2: "' & StringStripWS($array[2], 8) & '"' & @CRLF) ConsoleWrite('Column 4: "' & StringStripWS($array[4], 8) & '"' & @CRLF) Next This sample code will print: Column 2: "502" Column 4: "25.00" Column 2: "106" Column 4: "50.00" Col...

Python launcher functioning but not displaying any output

Python launcher functioning but not displaying any output I am using Pandas to read a CSV file that consists of names of stocks. After that, I am creating a new list where stocks that fit certain algorithms are appended; however, it only works with 8 - 9 stocks at a time. Is there somewhere I am making the code very inefficient and that can be optimized? Here is my code: import datetime as dt from dateutil.relativedelta import relativedelta import pandas as pd pd.core.common.is_list_like = pd.api.types.is_list_like import pandas_datareader.data as web import numpy as np import csv from mpl_finance import candlestick_ohlc import matplotlib.dates as mdates from matplotlib.dates import DateFormatter, MonthLocator, YearLocator, DayLocator, WeekdayLocator end = dt.date.today() start_48 = end - relativedelta( years=4 ) ticker_names = [ 'GGP', 'XLU', 'AAPL', 'AMZN', 'NVDA', 'XLI', 'XLP', 'ROL', 'MU', 'CAKE...

How to format TSV files to use with torchtext?

How to format TSV files to use with torchtext? The way i'm formatting is like: Jersei N atinge V média N . PU Programe V ... First string in each line is the lexical item, the other is a pos tag. But the empty-line (that i'm using to indicate the end of a sentence) gives me the error AttributeError: 'Example' object has no attribute 'text' when running the given code: AttributeError: 'Example' object has no attribute 'text' src = data.Field() trg = data.Field(sequential=False) mt_train = datasets.TabularDataset( path='/path/to/file.tsv', fields=(src, trg)) src.build_vocab(train) How the proper way to indicate EOS to torchtext? @kmario23 done! – Bledson Jul 3 at 17:43 You could replace the empty line with 2 TAB s. – Danny_ds ...

Adding custom variation field data to CSV order export - WooCommerce

Adding custom variation field data to CSV order export - WooCommerce I have been searching everywhere for an answer and just keep hitting road block after road block I have added custom variations fields in WooCommerce using http://www.remicorson.com/woocommerce-custom-fields-for-variations/ These fields save correctly when updating products. I have installed WooCommerce Customer / Order CSV Export and have added a meta_field column placing the meta_key found in the code below. Screenshot of the fields However when I export the CSV file the fields are empty. Anyone have any experience with getting the custom variation field data to appear when exporting order data via CSV. Listed below is the custom variation code being used. Any guidance would be greatly appreciated. /** * Create new fields for variations * */ function variation_settings_fields( $loop, $variation_data, $variation ) { // Text Field woocommerce_wp_text_input( array( 'id' ...

jq array of hashes to csv

jq array of hashes to csv So I have a data source like this: { "things": [ { "thing_name": "Bestco", "thing_id": 1 }, { "thing_name": "GreatCo", "thing_id": 2 }, { "thing_name": "DressCo", "thing_id": 3 } ] } I want to get output like this: $ echo '{"things":[{"thing_name":"Bestco","thing_id":1},{"thing_name":"GreatCo","thing_id":2},{"thing_name":"DressCo","thing_id":3}]}' | jq -r '.things | map(.thing_name, .thing_id, "n") | @csv' | sed -e 's/,"$//g' -e 's/^",//g' -e 's/^"$//g' "Bestco",1 "GreatCo",2 "DressCo",3 $ Using a fake parameter seems like a hack and then needs to be clean up by sed to work. How do I do this with just jq...