T
T
Timebird2017-12-23 10:49:18
Python
Timebird, 2017-12-23 10:49:18

How to iterate line by line in Pandas?

Let there be a dataframe:

0    1    2
1   248  109
2   765  783
3   143  146
4   111  167


You need to go through the lines and enter the minimum number from columns 1 and 2 in column 3.
Please tell me where to dig?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey, 2017-12-23
@Timebird

In your case, lambda functions are not really needed, there are shorter and faster options:

df['col3'] = df.min(axis=1)
# или
import numpy as np
df['col3'] = np.minimum(df.col1, df.col2)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question