0

I rephrased my question according to the question rules in hope that the new version is more appealing and in line with the standards. So I am trying to rank values within a dataframe based on the x-axis (axis = 1), to then (based on the respective ranking) modify my dataframe.

My idea was to create a function and .applymap() the function to the dataframe.


def rank_within_dataframe(x):

    if x in (df.rank(axis=1, pct=True))> 0.5:
        x = x^2
    else:
        x = "drop"

# for a 3*2 dataframe this function is supposed to -->

*Example Input:*


# data = [[-0.05, 0.24], [-0.20, 0.001], [0.25, 0.41]]
# df = pd.DataFrame(data, columns = ['Return1', 'Return2', 'Return3'])

import pandas as pd


data = [[-0.05, 0.24], [-0.20, 0.56], [0.25, 0.41]]
df = pd.DataFrame(data, columns = ['Return1', 'Return2'])

*desired Output:*

data = [['drop', 0.24], ['drop', 0.56], ['drop', 0.41]]
df = pd.DataFrame(data, columns = ['Return1', 'Return2'])

Yet this function is not working so far.

I am open to any ideas on how to solve this Problem and would highly appreicate your help - I am stuck here )-:

Cheers, Max

Max Bauer
  • 3
  • 3
  • Question 1) Write a function as a wrapper with dataframe as an input and same dataframe as an output. Question 2) Operator error – JJFord3 Aug 12 '19 at 14:56
  • 1
    Please see [How to make good reproducible pandas examples](https://stackoverflow.com/questions/20109391/how-to-make-good-reproducible-pandas-examples). – help-ukraine-now Aug 12 '19 at 14:56

0 Answers0