Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I think this is close to what you're looking for -- it's what I meant about putting the <code>if</code>statements from the two scripts inside a single<code>for</code>loop. It could be optimized, but I've tried to keep it simple so you can easily understand what is being done.</p> <pre><code>with open("inputcsv1.csv", "rt") as input_file: header = input_file.readline()[:-1] # remove trailing newline # add a title to the header for each of the two new columns header += ",Table exists?,Are you sure table exists?" output_lines = [header] for line in input_file: line = line[:-1] # remove trailing newline cols = line.split(',') # split line in columns based on delimiter # add first column if 'table' in cols[3]: line += ",table exists" else: line += ",No table found" # add second column if 'table' in cols[3]: line += ",table definitely exists" else: line += ",No table was not found" output_lines.append(line) with open("TestMurgedOutput.csv", "wt") as output_file: output_file.write("\n".join(output_lines)) </code></pre> <p>Contents of the <code>TestMurgedOutput.csv</code> file created:</p> <pre class="lang-none prettyprint-override"><code>title1,title2,title3,Table or no table?,title4,Table exists?,Are you sure table exists? data,text,data,the cat sits on the table,text,data,table exists,table definitely exists data,text,data,tables are made of wood,text,data,table exists,table definitely exists data,text,data,the cat sits on the television,text,data,No table found,No table was not found data,text,data,the dog chewed the table leg,text,data,table exists,table definitely exists data,text,data,random string of words,text,data,No table found,No table was not found data,text,data,table seats 25 people,text,data,table exists,table definitely exists data,text,data,I have no idea why I made this example about tables,text,data,table exists,table definitely exists data,text,data,,text,data,No table found,No table was not found </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload