import pandas as pd
import numpy as np
df = pd.read_csv ('input.csv')
df.head()
df['visibility'] = np.where(df['sku']== df['parent-sku'], 'visible', 'search') #add column if same sku in parent-sku
combo4 = df.groupby(['parent-sku'])['sku'].apply(', '.join)
data = print(combo4)
df['grouped items'] = np.where(df['sku']== df['parent-sku'], data, '') #format(combo2)
df.to_csv('output.csv', index=False)
So, my goal is to go over all CSV file, Check in column "PARENT-SKU" for repeating value in row, (4 items are same for exaple); take values from SKU column (each is unique) next to it; Merge with comma and append to new GROUPED column - only to first repeating of PARENT-SKU or only the one that has "VISIBLE"
Can't wrap my head around it. Whats wrong with it? Curent output on grouped items is NaN.
Example of data:
| Parent SKU | SKU | VISIBLE |
|---|---|---|
| A | A1 | VISIBLE |
| A | A2 | SEARCH |
| A | A3 | SEARCH |
| B | B1 | VISIBLE |
| B | B2 | SEARCH |
I get wery veird results, when tried with function, would love to see output:
| Parent SKU | SKU | VISIBLE | GROUPED ITEMS |
|---|---|---|---|
| A | A1 | VISIBLE | A1,A2,A3 |
| A | A2 | SEARCH | |
| A | A3 | SEARCH | |
| B | B1 | VISIBLE | B1,B2 |
| B | B2 | SEARCH |
Thanks a lot! And a beer for you!