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