I am using python to turn a CSV file into a dictionary, where the CSV file has multiple values for the same column.
The following works to use the CSV headers (first line) as the named key to turn a simple CSV without multiple values into a dictionary:
def main():
content = csvArray(".../Csv.csv")
print(content)
def csvArray(path):
df = pd.read_csv(path)
records = df.to_dict(orient='records')
return records
However, I now have an issue. There is an Image column in the CSV, and in many cases, there are multiple entries per column for 1 item, formatted like:
SKU | ImageData |
---|---|
12345 | 1st Image Data |
2nd Image Data | |
3rd Image Data | |
12346 | 1st Image Data |
2nd Image Data |
etc...
There can be anywhere up to 8 images for 1 SKU.
My csvArray function does not work with the CSV formatted as such, and changing the format of the CSV is not possible from the export.
How could I concatenate all the image data into the first row? Or any alternative that could work turning the CSV into a dictionary?