Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 23276

Surpringly difficult conversion from multi-line string to Pandas dataframe

$
0
0

I used a chatgpt AI assistant to pull data from a PDF which it did successfully. However I am struggling to convert this string output to a Python dictionary, though the ultimate goal is to make it a pandas data-frame.

The type(result) = str and if I print(result) the output is:

```python{'ReportDate': '11/30/2022','BankName': 'Bank ABC','Key 1': 194820,'Key 2': 24778,'Key 3': 1281778,'Key 4': 10943806,'in_thousands': True,'ReportName':'Report1'}```

Both ast.literal_eval(result), eval(result) aren't working.

Attempts and result:

Attempt 1:

y = eval(result)

Attempt 2:

import astresult = message_content.valuetemp_result =  result.replace('python', '', 1).strip()result_dict = ast.literal_eval(temp_result)

Both attempts result in a SyntaxError: invalid syntax pointing to

```python^

Viewing all articles
Browse latest Browse all 23276

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>