i have a df with tresholds and profits:
import numpy as np import pandas as pd
dates = pd.date_range('20130101',periods=6)
df = pd.DataFrame(np.random.randn(6,3),index=dates,columns=['Value1', 'Value2', 'Profit'])
df['Profit'] = df['Profit']*100
print(df.to_string())
total_profit = df['Profit'].loc[(df.Value1 > 0) & (df.Value2 >= 0)].sum()
print(total_profit)
is there a panda-way to optimize total_profit by finding the best fitting margings for the tresholds of filtering value1 and value2?
I mean i could loop over the DF and increase / decrease the filter-values until i find the best fitting value ... but i guess someone has already done this ... maybe sci-py?
so i basically need a function returning the best fits for value1 and value2, so i can filter my DF and optimize total_profit. the assumption is, that there is a correlation between value1, value2 and profit.
thanks and best wishes, e.
Value1andValue2such that when you filter your data by those thresholds the sum ofProfitis maximized?DataFrame.apply()may be a first step to look at.