I have quite large CSV files containing data about case verdicts from courts. I'm trying to create a script that searches the whole CSV file, and if a word is found, the whole row should be copied to a new CSV file.
I managed to create a script that can do that if there is just one word in each "cell" of the CSV, which isn't the case for me.
This is the Python script I'm working on:
# -*- coding: utf-8 -*-
import sys
import csv
import re
writeFile = open('verdictsOutput.csv', 'wb')
writer = csv.writer(writeFile)
with open('TestDomstol.csv', 'r') as verdictFileInput:
search = input("Enter keyword: ")
verdictFileReader = csv.reader(verdictFileInput, delimiter=';')
for row in verdictFileReader:
for field in row:
if field == search:
writer.writerow(row)
The TestDomstol.csv
looks like this (more than 1000 entries):
F1234;2019-09-22;Appeal over the decision bla bla, diaria number X regarding utility easement, compensation in Sweden;Utility easement;keyword
If I type in "keyword" in my Python script it works fine, because "keyword" is just one word in a cell. But what I want is to be able to type in and search for the word "compensation" (which is in the third column among a lot of other words).
Is there anyone who knows what changes need to be made? I have searched around on here, and Google, all morning, but I haven't been able to find some similar question or answer.