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?
JavaScript
x
11
11
1
QueryNumberZW = (ErgebnisPandas.query('Word=="ZW" & Wordindex<40 & Page==1').index.tolist())
2
print(QueryNumberZW)
3
4
if QueryNumberZW:
5
ResultNumberZW = (ErgebnisPandas['Wort'].iloc[QueryNumberZW[0]:QueryNumberZW[0]+3])
6
ResultNumberZW = ' '.join(ResultNumberZW)
7
8
print(ResultNumberZW)
9
10
´´´
11
Advertisement
Answer
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
JavaScript
1
10
10
1
# - at start -
2
all_words = []
3
4
# ... your code ...
5
all_words.append( word )
6
7
# - at the end -
8
df = pd.DataFrame({"words": all_words})
9
df.to_csv("words.csv")
10