Quantcast
Viewing all articles
Browse latest Browse all 14389

Use the first positiv number of a row if a certrain condition in another column is valid in pandas

I want to have the first non-negativ number in a new column, based on three columns (valueA, valueB, valueC) if a condition in columnA is valid. The condition is that columnA!=None. And an example dataframe df:

columnA  valueA valueB valueCNone        -40    -41   -42A           -5      10    20B           -10     -5    10C            1       2     3

would lead to:

columnA  valueA valueB valueC  valueDNone        -40    -41   -42    NoneA           -5      10    20     10B           -10     -5    10     10C            1       2     3      1

Viewing all articles
Browse latest Browse all 14389

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>