-1

I have dataframe with more than 100 features, half of it are numeric columns. I want to generate new features by dividing columns by each other. Is there an easy way to do it? Example:

df = pd.DataFrame(np.random.randint(0,100,size=(100, 4)), columns=list('ABCD'))
    A   B   C   D
0   6   53  75  65
1   26  93  5   0
2   48  5   13  95
3   8   93  50  41
4   62  32  99  5
5   66  55  92  61
6   72  77  52  13
7   40  13  94  90
8   48  22  41  17
9   11  42  76  9

I would like to get all possible combinations except dividing column by itself. Like this A/B, B/A, C/D, D/C, A/D...

  • 1
    What have you tried so far? – Meow_ly May 12 '22 at 15:49
  • @Meow_ly featuretools library, it has dataframe division option but i'd prefer to do it other way. – seems-to-work-enjoyer May 12 '22 at 15:53
  • 1
    Welcome to stack overflow. Unfortunately this is not a code-writing or tutorial site, and we ask that questions include a [mcve] in the text of your question showing sample input, expected output, and _code_ for what you've already tried based on your own research so that we can offer specific help and answers – G. Anderson May 12 '22 at 15:55

1 Answers1

1

With pandas you can divide each row in a column with the rows in another column by just dividing the columns themselves. I don't know if that is what you are looking for since the question is a bit vague.

df['new column'] = df['columnname1']/df['columnname2']
Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
Sabsa
  • 191
  • 9