tsv

Convert an array of json objects to tsv (python)

为君一笑 提交于 2019-12-03 22:17:21
Suppose that I have the following array of json objects, I want to convert them to the tsv format. [ { "x": "1", "y": "2", "z": "3" }, { "x": "6", "y": "7", "z": "B" } ] Does anyone have a good solution to this? (python's json module only allow reading json object, but how to read an array of json object?) x<TAB>y<TAB>z 1<TAB>2<TAB>3 6<TAB>7<TAB>8 The first step is to convert from a JSON string to an array of Python objects using, for example, json.loads . The final step is to write the Python objects to a file using, for example, csv.DictWriter . Here is a complete program that demonstrates

converting a d3.csv method to d3.csv.parse method

寵の児 提交于 2019-12-03 19:13:44
问题 I just need to draw a d3 barchart of data retrieved from an sql query, so I don't have a tsv or csv file but a string of data in csv format. I know I can use d3.csv.parse method but somehow I couldn't figure out how to convert the example code for the csv bar chart using the data from a file to csv.parse method for data contained in a string variable. here is the example code for csv file: d3.csv("data.csv", type, function(error, data) { x.domain(data.map(function(d) { return d.letter; })); y

How to test for blank text field when using robotframework-selenium?

浪尽此生 提交于 2019-12-03 11:28:45
How can I specify blank/empty value for a text field when using the robotframework-seleniumlibrary with a TSV file? For example, I have the following: Textfield Value Should Be identifier=name1 Chris Textfield Value Should Be identifier=name2 I want to test that name2 is blank. I have tried leaving it blank (which returns a message about an incorrect number of arguments. I have tried "", which looks for a pair of quotes, and '' which enters a single quote, and selenium seems to look for that janne You can use either a single backslash \ or special variable ${EMPTY} to create an empty string in

Postgres COPY FROM csv file- No such file or directory

情到浓时终转凉″ 提交于 2019-12-03 08:37:31
问题 I'm trying to import a (rather large) .txt file into a table geonames in PostgreSQL 9.1. I'm in the /~ directory of my server, with a file named US.txt placed in that directory. I set the search_path variable to geochat, the name of the database I'm working in. I then enter this query: COPY geonames FROM 'US.txt', DELIMITER E'\t', NULL 'NULL'); I then receive this error: ERROR: could not open file "US.txt" for reading: No such file or directory. Do I have to type in \i US.txt or something

Postgres COPY FROM csv file- No such file or directory

坚强是说给别人听的谎言 提交于 2019-12-02 22:27:59
I'm trying to import a (rather large) .txt file into a table geonames in PostgreSQL 9.1. I'm in the /~ directory of my server, with a file named US.txt placed in that directory. I set the search_path variable to geochat, the name of the database I'm working in. I then enter this query: COPY geonames FROM 'US.txt', DELIMITER E'\t', NULL 'NULL'); I then receive this error: ERROR: could not open file "US.txt" for reading: No such file or directory. Do I have to type in \i US.txt or something similar first, or should it just get it from the present working directory? Erwin Brandstetter A couple of

Extract data from tsv file python

半城伤御伤魂 提交于 2019-12-02 09:25:27
I have a TSV file, that looks like this: A B C D D=1;E=2 S D F G H=2;B=4 I'd like to write the contents to another tsv file in this way. A B C D D 1 A B C D E 2 S D F G H 2 S D F G B 4 I'd really appreciate if anyone could help/ hint me in splitting column 5 as desired. If you are positively sure you only have tabs and semicolons, then you can use split. with open('/tmp/test.tsv') as infile, open('/tmp/test2.tsv', 'w') as outfile: for line in infile: tsplit = line.split("\t") firstcolumns = tsplit[:-1] lastitems = tsplit[-1].strip().split(";") for item in lastitems: allcolumns = firstcolumns +

python chain a list from a tsv file

烂漫一生 提交于 2019-12-02 03:29:33
i have this tsv file containing some paths of links each link is seperated by a ';' i want to use: In the example below we can se that the text in the file is seperated and i only want to read through the last column wich is a path starting with '14th' 6a3701d319fc3754 1297740409 166 14th_century;15th_century;16th_century;Pacific_Ocean;Atlantic_Ocean;Accra;Africa;Atlantic_slave_trade;African_slave_trade NULL 3824310e536af032 1344753412 88 14th_century;Europe;Africa;Atlantic_slave_trade;African_slave_trade 3 415612e93584d30e 1349298640 138 14th_century;Niger;Nigeria;British_Empire;Slavery

R reading a tsv file using specific encoding

岁酱吖の 提交于 2019-12-01 16:18:45
I am trying to read a .tsv (tab-separated value) file into R using a specific encoding. It's supposedly windows-1252 . And it has a header. Any suggestions for the code to put it into a data frame? Something like this perhaps? mydf <- read.table('thefile.txt', header=TRUE, sep="\t", fileEncoding="windows-1252") str(mydf) Frederica Stahl You can also use: read.delim('thefile.txt', header= T, fileEncoding= "windows-1252") Simply entering the command into your R consol: > read.delim function (file, header = TRUE, sep = "\t", quote = "\"", dec = ".", fill = TRUE, comment.char = "", ...) read.table

R reading a tsv file using specific encoding

戏子无情 提交于 2019-12-01 15:10:07
问题 I am trying to read a .tsv (tab-separated value) file into R using a specific encoding. It's supposedly windows-1252 . And it has a header. Any suggestions for the code to put it into a data frame? 回答1: Something like this perhaps? mydf <- read.table('thefile.txt', header=TRUE, sep="\t", fileEncoding="windows-1252") str(mydf) 回答2: You can also use: read.delim('thefile.txt', header= T, fileEncoding= "windows-1252") Simply entering the command into your R consol: > read.delim function (file,

How do I convert a .tsv to .csv?

青春壹個敷衍的年華 提交于 2019-11-30 20:28:05
Trying to convert a .tsv to a .csv. This: import csv # read tab-delimited file with open('DataS1_interactome.tsv','rb') as fin: cr = csv.reader(fin, delimiter='\t') filecontents = [line for line in cr] # write comma-delimited file (comma is the default delimiter) with open('interactome.csv','wb') as fou: cw = csv.writer(fou, quotechar='', quoting=csv.QUOTE_NONE) cw.writerows(filecontents) Gives me this error: File "tsv2csv.py", line 11, in <module> cw.writerows(filecontents) _csv.Error: need to escape, but no escapechar set While attempting to write to the CSV file, it encounters a token where