'Is it possible to use numpy.select() with a DataFrame where the choicelist depends on one or more column
I am trying to create an array using numpy.select() on my dataframe and I would like to know if it's possible to make my choicelist variable. For example here is my DataFrame:
face matériau profilé ext1_1 ext1_2 ext2_1 ext2_2 longeur cl
0 1 A588 UPN 80/0 0 0 5 5 7.071 3
1 0 A514 T 50/2 0 0 5 5 7.071 2
2 2 A514 T 80/2 1 2 5 4 7.071 2
conditions = [df['face'] == 0, df['face'] == 1, df['face'] == 2, df['face'] == 3, df['face'] == 4, df['face'] == 5]
outputs1 = [
[df.loc[df.index]['ext1_1'], 0, df.loc[df.index]['ext1_2']],
[0, df.loc[df.index]['ext1_1'], df.loc[df.index]['ext1_2']],
[x_max, df['ext1_1'], df.loc[df.index]['ext1_2']],
[df.loc[df.index]['ext1_1'], y_max, df.loc[df.index]['ext1_2']],
[df.loc[df.index]['ext1_1'], df.loc[df.index]['ext1_2'], z_max],
[df.loc[df.index]['ext1_1'], df.loc[df.index]['ext1_2'], 0]
]
array= np.select(conditions, outputs1)
So for example:
if face == 1 I want as result : [0,0,0]
if face == 2 I want as result : [x_max, 1, 2] etc...
My code throw the error: ValueError: shape mismatch: objects cannot be broadcast to a single shape So i think there is a problem whith my choicelist
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
