OpenAI + Pandas is a total nightmare for SKU generation

cpuonly_sad78 Beginner 4d ago 197 views 0 likes 2 min read

Trying to automate this SKU coding mess with a Python script has been a massive headache because the data handling part is just absolute garbage right now. I'm basically trying to scrape product descriptions from a CSV and turn them into these weird standardized strings like 100-010-8kg-Active, but the DX of trying to pipe this into an LLM without everything exploding is zero. I've got the OpenAI SDK doing the actual heavy lifting for the text mapping, but since the dataset is massive, my current logic of loading it into a Pandas DataFrame and then manually partitioning rows into chunks feels like a complete hack. I’m constantly fighting token limits and timeouts, and the thought of trying to "stitch" these processed chunks back into the original DataFrame without the index alignment going to hell is giving me actual anxiety. If I mess up the merge, I'm just going to end up with a corrupted CSV full of duplicate rows and I'll want to throw my monitor out the window. And don't even get me started on the latency—doing an API call for every single row is going to take literal ages unless I figure something out. I don't know if there's some secret Pandas trick I'm missing or if I just need to go full async with the OpenAI client to stop this thing from crawling at a snail's pace. I'm terrified that if one API call fails mid-batch, the whole process is going to wreck my data integrity. Here is the current prototype that is basically just a bottleneck in a trench coat:

import os 
from dotenv import load_dotenv
from openai import OpenAI

load_dotenv()

OPEN_API_KEY = os.getenv("OPEN_API_KEY")
client = OpenAI(api_key = OPEN_API_KEY)

with open("./utilities/instructions.txt") as inst:
instructions = inst.read()

This is where the bottleneck happens


new_sku_code = client.responses.create(
model = "gpt-4o", # Using current available models
instructions = instructions,
input = "Active - Champion Kettlebell 8kg"
)

print(new_sku_code.output_text)

Has anyone actually dealt with large-scale data transformations using LLMs and Pandas without losing their mind? I need a way to make this partitioning and merging process actually robust so I'm not just praying to the dev gods every time I run the script.

Help Needed

All Replies (3)

P
phdinml Beginner 4d ago
Tried this last month and the API latency completely killed my script's performance. Total waste of time.
0 Reply
L
latentspace Expert 4d ago
Same thing happened to me, I ended up batching the requests to keep the memory usage stable.
0 Reply
M
mistraluser17 Expert 4d ago
I tried using chunksize in Pandas to avoid memory errors when passing large rows to the API.
0 Reply

Write a Reply

Markdown supported