user11218700
user11218700

Reputation:

How to extract a particular values from a txt file and make those all into df

have a txt file contains many values

Used regex

'many_espd': '(\d+)'

This gets my requirement but how to take all those values and make it a df

Upvotes: 0

Views: 37

Answers (1)

Tim Biegeleisen
Tim Biegeleisen

Reputation: 521639

Try this option, which creates a single column data frame from your list of matching digits:

result_list = re.findall(r"'many_espd': '(\d+)'", text)
df = DataFrame({'espd': result_list})

Note that if you are actually using regex to parse JSON content, then stop here, and instead look into using a JSON parser.

Upvotes: 1

Related Questions