lundi 22 février 2016

Random selection in pandas dataframe

Given df

a    b
1    2
5    0
5    9
3    6
1    8

How can I create a column C that is a random selection between the two elements of df['a'] and df['b'] of the same row?

So, given this dummy df, the random operator would choose from the pair (1, 2) for row #1, from (5, 0) for row #2...etc.

Thanks




Aucun commentaire:

Enregistrer un commentaire