this is a part of my OCR code. This part looks for a special word in a scanned PDF and prints this out. I have like 10 Queries like this and all print me the word I am looking for. Now I want to get the found words saved in a CSV, but I don't know how to do that. Can Someone help me, please?
QueryNumberZW = (ErgebnisPandas.query('Word=="ZW" & Wordindex<40 & Page==1').index.tolist())
print(QueryNumberZW)
if QueryNumberZW:
ResultNumberZW = (ErgebnisPandas['Wort'].iloc[QueryNumberZW[0]:QueryNumberZW[0] 3])
ResultNumberZW = ' '.join(ResultNumberZW)
print(ResultNumberZW)
´´´
CodePudding user response:
It is basic knowledge.
Create empty list at start, append() words to list, and later write all list using csv
or pandas
I have no idea which variables you want to save
# - at start -
all_words = []
# ... your code ...
all_words.append( word )
# - at the end -
df = pd.DataFrame({"words": all_words})
df.to_csv("words.csv")