File tree 1 file changed +6
-5
lines changed 1 file changed +6
-5
lines changed Original file line number Diff line number Diff line change @@ -1167,18 +1167,19 @@ An alternative to :meth:`~pandas.DataFrame.where` is to use :func:`numpy.where`.
1167
1167
Combined with setting a new column, you can use it to enlarge a dataframe where the
1168
1168
values are determined conditionally.
1169
1169
1170
- When you have two choices to choose from, say in the following dataframe, set the color
1171
- to 'green' when the second column has 'Z'. You can do the following:
1170
+ Consider you have two choices to choose from in the following dataframe. And you want to
1171
+ set a new column color to 'green' when the second column has 'Z'. You can do the
1172
+ following:
1172
1173
1173
1174
.. ipython :: python
1174
1175
1175
1176
df = pd.DataFrame({' col1' : list (' ABBC' ), ' col2' : list (' ZZXY' )})
1176
1177
df[' color' ] = np.where(df[' col2' ] == ' Z' , ' green' , ' red' )
1177
1178
df
1178
1179
1179
- If you have more than one conditions, you can use :func: `numpy.select ` to achieve that.
1180
- Say corresponding to three conditions there are three choice of colors, with a fourth
1181
- color as a fallback, you can do the following.
1180
+ If you have multiple conditions, you can use :func: `numpy.select ` to achieve that. Say
1181
+ corresponding to three conditions there are three choice of colors, with a fourth color
1182
+ as a fallback, you can do the following.
1182
1183
1183
1184
.. ipython :: python
1184
1185
You can’t perform that action at this time.
0 commit comments