I am trying to retrieve amounts from each word document eg. 'Amount:500', 'Amount:4000',etc. but the amounts are not always in the same index. Could someone point me in the right direction, searching for this changing string in each file where 'Amount:' is the only consistent aspect. Is this possible to achieve? Thanks
Asked
Active
Viewed 20 times
-2
-
1you can find the word "Amount:" in the text and then retrieve the value. Take a look at https://stackoverflow.com/questions/674764/examples-for-string-find-in-python – Jun 15 '22 at 10:31
-
1Yes, it is possible, in a number of different ways. Please, check [ask]. Right now your question is way too broad – buran Jun 15 '22 at 10:35
1 Answers
1
Search for the token "Amount:" in your text to retrieve the value
# toy example
convertedText = "erfjnerk rfonerf rfnerf Amount:4000 erfjn"
# find the token "Amount:"
idx = convertedText.find("Amount:")
# crop anything before the value
value = convertedText[idx+len("Amount:"):]
# split, crop anything after the value and convert to an int.
# Here I assumed a space after the value, change it to fit your format (eg: newline)
value = int(value.split()[0])
Result
4000
-
-
well, if the Amount is not an int convert it to float, but in the question it is an int. – Jun 15 '22 at 13:33