lisstasy commited on
Commit
b4fcc21
·
verified ·
1 Parent(s): ea46450

Update code.py

Browse files
Files changed (1) hide show
  1. code.py +7 -1
code.py CHANGED
@@ -505,7 +505,13 @@ def structured_output(texts, api_key):
505
  # Transform items data to dataframe
506
  items_df = pd.DataFrame(data.get('items', []))
507
 
508
- for column in ['unit', 'price', 'amount']:
 
 
 
 
 
 
509
  items_df[column] = pd.to_numeric(items_df[column], errors='coerce')
510
 
511
  items_df = ensure_category(items_df)
 
505
  # Transform items data to dataframe
506
  items_df = pd.DataFrame(data.get('items', []))
507
 
508
+ # Fill 'unit' column with 1 if it is missing
509
+ if 'unit' not in items_df.columns:
510
+ items_df['unit'] = 1
511
+ else:
512
+ items_df['unit'] = pd.to_numeric(items_df['unit'], errors='coerce').fillna(1)
513
+
514
+ for column in ['price', 'amount']:
515
  items_df[column] = pd.to_numeric(items_df[column], errors='coerce')
516
 
517
  items_df = ensure_category(items_df)