I am trying to get the column count from an output csv file using Robot script.
I tried the following lines. Count of rows is working fine. But the 'Get Column Count' is throwing error :
No keyword with name 'Get Column Count' found.
${file-content}= Get File ${OUTPUT_CSV_FILE}
${numberOfLine=}= Get Line Count ${file-content}
Should Be Equal As Integers ${numberOfLine=} X
${numberOfColumn=}= Get Column Count ${file-content}
Should Be Equal As Integers ${columnCount=} Y
I haven't defined any keywords for 'Get Line Count'..but its working.
Then why not Get Column Count. Is it necessary to write a keyword in robot?
Thanks in advance
Aneesh
I haven't defined any keywords for 'Get Line Count'..but its working. Then why not Get Column Count. Is it necessary to write a keyword in robot?
The reason why "Get line count" is working is that you have likely imported robot's String library which has a keyword named Get Line Count. It's not counting rows in a csv file, it's counting lines of text by splitting the string on newlines.
Robot doesn't itself have a keyword for counting columns in a csv file. For that you'll need to use a library that specifically imports the data as csv and has a keyword for counting columns.
Related
I have an application where I create a .csv file and then create a .xlsx file from the .csv file. The problem I am having now is that the end of rows in the .csv have a trailing space. My database is in MarkLogic and I am using a custom REST endpoint to create this. The code where I create the .csv file is:
document{($header-row,for $each in $data-rows return fn:concat('
',$each))}
I pass in the header row then pass each data row with a carriage return and a line feed at the beginning. I do this to put the cr/lf at the end of the header and then each of the other lines except for the last one. I know my data rows do not have the space at the end. I have tried to normalize the space around $each and the extra space is still present. It seems to be tied to the line feed. Any suggestions on getting rid of that space?
Example of current output:
Name,Email,Phone
Bill,bill#company.com,999-999-9999
Steve,steve#company.com,999-999-9999
Bob,bob#company.com,999-999-9999
. . .
You are creating a document that is text() node from a sequence of strings. When those are combined to create a single text(), they will be separated by a space. For instance, this:
text{("a","b","c")}
will produce this:
"a b c"
Change your code to use string-join() to join your $header-row and sequence of $data-rows string values with the
separator:
document{ string-join(($header-row, $data-rows), "
") }
try to upload CSV data with a case statement in the query, but the following error appears:
cypher:
USING PERIODIC COMMIT
LOAD CSV WITH HEADERS FROM 'file:///test.csv' as line
MATCH(a:test_t{tid:line.pid})
CASE
WHEN line.key !='NA' THEN
WITH split(line.key,",") as name
UNWIND name as x
MERGE(k:test_key{key_term:toLower(x)})
MERGE(a)-[:contains]->(k)
END
Error
Neo.ClientError.Statement.SyntaxError: Invalid input 'S': expected 'l/L' (line 5, column 3 (offset: 137))
"CASE"
Can anyone help me?
The CASE clause does not support embedding other Cypher clauses (but it can invoke functions). In fact, a CASE clause is not actually needed for your use case.
This query should work (the :auto at the beginning is needed in neo4j 4.0+):
:auto USING PERIODIC COMMIT
LOAD CSV WITH HEADERS FROM 'file:///test.csv' as line FIELDTERMINATOR ';'
WITH line
WHERE line.key <> 'NA'
MATCH (a:test_t {tid: line.pid})
UNWIND split(line.key, ',') as x
MERGE (k:test_key {key_term: TOLOWER(x)})
MERGE (a)-[:contains]->(k)
This query filters out all unwanted lines as soon as they are obtained from the file. Reducing the number of rows of data being worked on as early as possible is good practice.
Also, you have a second issue. Your data file cannot use the comma as both the (default) field terminator AND as the delimiter between your x values.
To resolve this ambiguity, the above query chose to use the FIELDTERMINATOR ';' option to specify that the ";" character will be used as the field terminator. A sample data file would look like this:
pid;key
123;NA
234;Foo,Bar
345;Bar,Baz
456;NA
567;Baz
You are using the CASE incorrectly. You cannot have update clauses inside of a CASE statement. Instead you can use a WHERE clause to filter the rows of the file. For instance, adding WHERE line.key != 'NA' while processing the file befor you move onto the update will work. Something like this should fit the bill.
USING PERIODIC COMMIT
LOAD CSV WITH HEADERS FROM 'file:///test.csv' as line
MATCH (a:test_t {tid: line.pid})
WITH line
WHERE line.key <> 'NA'
WITH split(line.key, ",") as name
UNWIND name as x
MERGE (k:test_key {key_term: toLower(x)})
MERGE (a)-[:contains]->(k)
It looks like,from your logic you could even move the test up above the MATCH. So this might be better (fewer unecessary matches).
USING PERIODIC COMMIT
LOAD CSV WITH HEADERS FROM 'file:///test.csv' as line
WITH line
WHERE line.key <> 'NA'
MATCH (a:test_t {tid: line.pid})
WITH split(line.key, ",") as name
UNWIND name as x
MERGE (k:test_key {key_term: toLower(x)})
MERGE (a)-[:contains]->(k)
this is the excel:
enter image description here
I want to get the first column's cell count, I use excellibrary, but the Get Row Count method doesn't suite my case, it get the max row in excel,any solution?
my code as below(i use ride):
Open Excel | D:\\try.xls
${a} | Get Column Count | Sheet1
the result is 4, but i want to get 3
The excellibrary uses internally a python lib for working with Excel files - xlrd; the keyword Get Column Count is actually returning the property ncols of a Sheet object in it, the documentation of which says:
Nominal number of columns in sheet. It is one more than the maximum column index found, ignoring trailing empty cells.
So it will always return one more than the actual used - just subtract the extra one.
I have a folder with tons of txt files from where I have to extract especific data. The problem is that the format of the file has changed once and the position of the data I need to extract has also changed. So I need to deal with files in different format.
To try to make it more clear, in column 4 I have the name of the variable and in 5 I have the value, but sometimes this is in a different row. Is there a way to find the name of the variable (in which row) and then extract its value?
Thanks in advance
EDITING
In some files I will have the data like this:
Column 1-------Column 2.
Device ID------A.
Voltage------- 500.
Current--------28
But in some point in life, there was a change in the software to add another variable and the new file iis like this:
Column 1-------Column 2.
Device ID------A.
Voltage------- 500.
Error------------5.
Current--------28
So I need to deal with these 2 types of data, extracting the same variables which are in different rows.
If these files can't be read with read.table use readLines and then find those lines that start with the keyword you need.
For example:
Sample file 1 (with the dashes included and extra line breaks):
Column 1-------Column 2.
Device ID------A.
Voltage------- 500.
Error------------5.
Current--------28
Sample file2 (with a comma as separator):
Column 1,Column 2.
Device ID,A.
Current,555
Voltage, 500.
Error,5.
For both cases do:
text = readLines(con = file("your filename here"))
curr = text[grepl("^Current", text, ignore.case = T)]
Which returns:
for file 1:
[1] "Current--------28"
for file 2:
[1] "Current,555"
Then use gsub to remove anything that is not a number.
I want to read multiple images which are in a folder in Scilab. My code is:
I1=dir('G:\SCI\FRAME\*.jpg');
n=length(I1);
disp(n);
for i=1:n
I2=strcat('G:\SCI\FRAME\',I1(i).name);
I=imread(I2);
figure(),imshow(I);
end
But it does not work. It shows error "invalid index".
There are two mistakes to correct:
1.) length gives the number of characters (=length) of a string, but you want to get the number of elements (=size) in a vector (the filenames), hence you should use size.
2.) I1 is a list structure returned by dir. You can extract its content with the . operator, e.g. I1.name, I1.date, I1.bytes, I1.isdir. Type these into the consol, to see the contents! Since I1.name already contains the fullpath+filename+extension as a string vector, you don't have to construct it with strcat. Anyway if you want to "glue" 2 strings together, it's easier to use + e.g. S="fisrst_string"+"second_string".
So the revised code:
I1=dir('G:\SCI\FRAME\*.jpg');
n=size(I1.name,"*"); //size of the I1.name vector
disp(n);
for i=1:n
I=imread(I1.name(i)); //I1.name is a string vector
figure();
imshow(I);
end