0

I originally asked the question in the following link which was answered well. Please just review for reference sake:

based on dataframe column result all following rows equal a repetitive value until result changes and new repetitive value occurs

Assume I have the follwing output:

import pandas as pd
df = pd.DataFrame()
df['A'] = ('0','0','0','0','0','0','YES','0','YES','YES','YES','0','0','0','0','YES','0','0','0','0','0','0','0','0', 'NO','0','0','0','0')

df['B'] = ('1','','','3','2','1','','','','','','','','','','','','','','','','','','', '8','','','','')

df['C'] = ('','','','','','','9','','','','','','','','','9','8','7','6','5','4','3','2','1', '','','','','')
print(df)

I have a follow up problem whereby I wish the following:

  1. if a NO on column (col) A occurs with either an 8 or 9 on col B than col D also is NO. Only f it is followed by a 1 on col C then col D is BAD. BAD is continued up to 9 or if no greater number occurs on col C

  2. if a YES on column (col) A occurs with either an 8 or 9 on col C than col D also is YES. Only if it is followed by a 1 on col B then col D is GOOD. GOOD is continued up to 9 or if no greater number occurs on col B

I might be missing a rule or 2 but if you can make the dataframe look like following I think it is on the right track

Basically I am aiming for the output to look as follows:

df['D'] = ('','','','GOOD','GOOD','GOOD','YES','','','','','','','','','YES','BAD','BAD','BAD','BAD','BAD','BAD','BAD','BAD', 'NO','','','','')

print(df)
ds882
  • 105
  • 11
  • hey ds882, no one here can interpolate your business logic for you, you need to explicit tell us the rules for anyone to translate that into code, tbf I'm finding it hard to conceptualise your request. Also what have you tried? – Umar.H Oct 15 '19 at 11:57
  • I apologies, I have tried via my actual real life program but found myself creating more and more dataframe columns without solving the problem. I tried to encapsulate what I required in an example but it may be no explained appropriately – ds882 Oct 15 '19 at 12:04
  • I will remove this request and improve my question if I receive no feedback by tomorrow – ds882 Oct 15 '19 at 12:05
  • no need to apologise, just think of the end user, if you can't understand your own request, then we can't either. check out [How to make good reproducible pandas examples](https://stackoverflow.com/questions/20109391/how-to-make-good-reproducible-pandas-examples) – Umar.H Oct 15 '19 at 12:08

0 Answers0