Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 13891

I have a dataframe with input column and need to create another column based on input column with some conditions (use numpy.select() to solve it)

$
0
0

x = {"INPUT" : ['A','B','B','B','B','B','A','B','B','C','B','B','C','B','B','A','B','C']}df = pd.DataFrame(x)df

Condition for calculation of “OUTPUT” column

condition(1)if INPUT value A then OUTPUT 1

condition(2)if INPUT value C then OUTPUT -1

condition(3.i)if INPUT value B and B present after C then OUTPUT -1

condition(3.ii.a)if INPUT value B and B present after A and upto 3 consecutive INPUT value of B then OUTPUT 1

condition(3.ii.b)if INPUT value B and B present after A and after 3 consecutive INPUT value of B then OUTPUT -1

FINAL DATAFRAME


Viewing all articles
Browse latest Browse all 13891

Trending Articles



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