0

I am trying to make two new groups, one with continuous variable y's data where answer X is "Yes", and another where the X is "No". The two lists should contain the two different groups' corresponding Y scores.

I've tried some variations and different code but nothing has let me take the value 'X' to return another in the data frame that keeps the list unique, or runs.

I used this: for ind in do.index: if re.search('No', do['X'][ind]): dk['opn'] = do['Y'] And it returned the same Y for both 'No' and 'Yes', making identical lists. This occurred when I did them separately or together in the same function. I also tried: for col in do.columns: if (do[col].nunique()<=4) & (col not in cols_to_exclude): do[col] = do[col].astype('category') And it returned: unsupported operand type(s) for &: 'int' and 'str' I also tried this: for c in do['X']: if c == 'Yes': opy.append(do['Y']) But I got the list repeated MANY times without error or clear reason, within the variable I'd made, repeating the list over and over. Both list logics for no or yes also produced the same list.

The variable contents looked like this but many times over: Name: Y, Length: 208, dtype: float64, 459 10.0 461 10.0 463 5.0 465 9.0 466 9.0 ... 1075 7.0 1079 9.0 1081 9.0 1084 7.0 1089 8.0 Name: Y, Length: 208, dtype: float64, 459 10.0 461 10.0 463 5.0 465 9.0 466 9.0 ... 1075 7.0 1079 9.0 1081 9.0 1084 7.0 1089 8.0

SyKG
  • 1
  • Please [edit] your post and provide a complete [minimal reproducible example](https://stackoverflow.com/help/minimal-reproducible-example) with sample input, code that we can copy-paste and run to reproduce your issue(s), and desired output. Currently, we cannot do anything with your code snippets, as you have not explained what each variable is (besides Y). Please see [how to ask a good question](https://stackoverflow.com/help/how-to-ask) for more tips, as well as [How to make good reproducible pandas examples](https://stackoverflow.com/questions/20109391). – AlexK Mar 17 '23 at 22:18

0 Answers0