rcai commited on
Commit
d6b7e8f
·
verified ·
1 Parent(s): ab3ed4a

Update test.py

Browse files
Files changed (1) hide show
  1. test.py +34 -0
test.py CHANGED
@@ -1,6 +1,40 @@
1
  import pandas as pd
2
  import re
3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4
 
5
  json_string = re.search(r"```(.*?)```", llm_output, re.DOTALL).group(1).strip()
6
 
 
1
  import pandas as pd
2
  import re
3
 
4
+ import json
5
+ import pandas as pd
6
+ import re
7
+
8
+ # The text output from the LLM (you would replace this with the actual output)
9
+ llm_output = """
10
+ ... [Your provided text goes here] ...
11
+ """
12
+
13
+ # Extract JSON strings using regex
14
+ json_strings = re.findall(r'```json\n(.*?)```', llm_output, re.DOTALL)
15
+
16
+ # Parse each JSON string and collect the data
17
+ data = []
18
+ for json_str in json_strings:
19
+ try:
20
+ parsed = json.loads(json_str)
21
+ entity_name = parsed['entity_name']
22
+ attributes = parsed['attributes'][0]
23
+ attributes['entity_name'] = entity_name
24
+ data.append(attributes)
25
+ except json.JSONDecodeError:
26
+ print(f"Error parsing JSON: {json_str}")
27
+
28
+ # Create a pandas DataFrame
29
+ df = pd.DataFrame(data)
30
+
31
+ # Reorder columns to have 'entity_name' first
32
+ cols = ['entity_name'] + [col for col in df.columns if col != 'entity_name']
33
+ df = df[cols]
34
+
35
+ # Display the DataFrame
36
+ print(df)
37
+
38
 
39
  json_string = re.search(r"```(.*?)```", llm_output, re.DOTALL).group(1).strip()
40