0

Here are 4 rows and 4 columns.

a b c d
1 8 2 6
3 6 7 9
1 5 9 4
1 0 6 8

I want column 'e' as shown below but below code gives me NaN as output in entire 'e' column.

df["e"]= df.loc[:, ["b", "c", "d"].min()

Desired Output

a b c d e
1 8 2 6 1
3 6 7 9 3
1 5 9 4 1
1 0 6 8 0
Balaji Ambresh
  • 4,977
  • 2
  • 5
  • 17
Parth Bute
  • 17
  • 4

2 Answers2

0

Use

df['e'] = df.min(axis=1)

That'll get your the minimum across all columns, row wise.

Balaji Ambresh
  • 4,977
  • 2
  • 5
  • 17
0

df["e"]= df.loc[:, ["b", "c", "d"]].min(axis = 1) instead as it has to give the minimum by itering in columns.

Divyessh
  • 2,540
  • 1
  • 7
  • 24