Last active
December 19, 2021 13:44
-
-
Save fanian/a4606b5de25922e0cb58c359c49d6b78 to your computer and use it in GitHub Desktop.
continues alternative groups in BOM
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
# Create DataFrame | |
df = pd.read_csv('data.csv') | |
jnum = 1 | |
#loop through each row of dataframe (not including the first/zeroeth) | |
df['Global group'].loc[0] = jnum | |
for i in range(1,len(df)): | |
if df.BOM.loc[i] == df.BOM.loc[i-1] and df['Group'].loc[i] == df['Group'].loc[i-1]: | |
df['Global group'].loc[i] = jnum | |
else: | |
jnum += 1 | |
df['Global group'].loc[i] = jnum | |
for m in range(0,len(df)): | |
df['Class'].loc[m] = df['Global group'].loc[m] | |
for k in range(0, len(df)): | |
for l in range(k,len(df)): | |
if df['Material'].loc[k] == df['Material'].loc[l]: | |
df['Class'].loc[l] = df['Class'].loc[k] | |
groupn = df['Global group'].loc[l] | |
for m in range(k, len(df)): | |
if df['Global group'].loc[m] == groupn: | |
df['Class'].loc[m] = df['Class'].loc[k] | |
print(df) | |
#df.to_csv('data.csv') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
BOM | Material | Group | Global group | Class | |
---|---|---|---|---|---|
A-Bom | Cabel1 | 1 | 1.0 | 1.0 | |
A-Bom | Cabel2 | 1 | 1.0 | 1.0 | |
A-Bom | HDD1 | 2 | 2.0 | 2.0 | |
A-Bom | HDD2 | 2 | 2.0 | 2.0 | |
B-Bom | Cabel2 | 4 | 3.0 | 1.0 | |
B-Bom | Cabel3 | 4 | 3.0 | 1.0 | |
C-Bom | MB1 | 1 | 4.0 | 4.0 | |
C-Bom | HDD1 | 5 | 5.0 | 2.0 | |
C-Bom | HDD2 | 5 | 5.0 | 2.0 | |
D-Bom | MB1 | 1 | 6.0 | 4.0 | |
D-Bom | MB3 | 1 | 6.0 | 4.0 | |
D-Bom | HDD2 | 2 | 7.0 | 2.0 | |
bom5 | MB3 | 4 | 8.0 | 4.0 | |
bom5 | motherbo2 | 4 | 8.0 | 4.0 | |
22bom | Cabel5 | 4 | 9.0 | 9.0 | |
22bom | HDD1 | 5 | 10.0 | 2.0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment