Pandas: get the min value between 2 dataframe columns
问题 I have 2 columns and I want a 3rd column to be the minimum value between them. My data looks like this: A B 0 2 1 1 2 1 2 2 4 3 2 4 4 3 5 5 3 5 6 3 6 7 3 6 And I want to get a column C in the following way: A B C 0 2 1 1 1 2 1 1 2 2 4 2 3 2 4 2 4 3 5 3 5 3 5 3 6 3 6 3 7 3 6 3 Some helping code: df = pd.DataFrame({'A': [2, 2, 2, 2, 3, 3, 3, 3], 'B': [1, 1, 4, 4, 5, 5, 6, 6]}) Thanks! 回答1: Use df.min(axis=1) df['c'] = df.min(axis=1) df Out[41]: A B c 0 2 1 1 1 2 1 1 2 2 4 2 3 2 4 2 4 3 5 3 5 3