I have a huge df that looks like this:
| date | stock1 | stock2 | stock3 | stock4 | stock5 | stock6 | stock7 | stock8 | stock9 | stock10 |
|---|---|---|---|---|---|---|---|---|---|---|
| 10/20 | 0.1 | 0.2 | 0.3 | 0.4 | 0.5 | 0.6 | 0.7 | 0.8 | 0.9 | 0.9 |
| 11/20 | 0.8 | 0.9 | 0.3 | 0.4 | 0.3 | 0.5 | 0.3 | 0.2 | 0.4 | 0.1 |
| 12/20 | 0.3 | 0.6 | 0.9 | 0.5 | 0.6 | 0.7 | 0.8 | 0.7 | 0.9 | 0.1 |
I want to find, for each row, the 20% higher values of stocks and the 20% lower. The output should be:
| date | higher | lower |
|---|---|---|
| 10/20 | stock9, stock 10 | stock1, stock 2 |
| 11/20 | stock1, stock 2 | stock8, stock 10 |
| 12/20 | stock3, stock 9 | stock1, stock 10 |
I do not need to have the comma between the values above, could be one below the other.
I have tried df= df.stack() for stacking and later rank the values inside the columns, but I do not know how to proceed.
