I am new to Python, so please forgive me. I have pieced this together through things i've found online, however, it's still not working exactly as it should.
I'm wanting a python script that will look in a given spreadsheet (list.csv), parse it for any "key_words", then export a file of only the rows that DO NOT contain any "key_words" called "cleaned.csv". I would like for it to only look in the first column, [0]. If possible, I would like for it to also export me a second spreadsheet of the ones that DO contain keywords, just to verify what it is scraping out.
This current code looks at the entire csv file and I see it not putting some of the rows in "cleaned.csv", when technically, it should be, unless there is a problem with my array.
Here is my current code...
key_words = [ 'Dog', 'Cat', 'Bird', 'Cow', ]
with open('list.csv') as oldfile, open('cleaned.csv', 'w') as newfile:
for line in oldfile:
if not any(key_word in line for key_word in key_words):
newfile.write(line)
First couple rows of data are...
Dog,Walks,Land,4legs,
Fish,Swims,Water,fins,
Kangaroo,Hops,Land,2legs,
Cow,Walks,Land,4legs,
Bird,Flies,Air,2legs,
Cleaned.csv should show:
Fish,Swims,Water,fins,
Kangaroo,Hops,Land,2legs,
Other.csv (bad, matching array) should show:
Dog,Walks,Land,4legs,
Cow,Walks,Land,4legs,
Bird,Flies,Air,2legs,