last day (15 days later) » 

1:05 PM
Hi
 
hi
 
so lets discuss solution
I have actually implemented it but it is not good and I want it to be automated.
This is example I am using.
n = 100000
col = 'city_pop'
x = pd.DataFrame({'city_pop': [234, 43344, 83434, 3433424]})
n is given value
this is my code, I know its not understandable but I will explain.
def sum_col(col, val, x):
x['diff_to_n'] = (x[col] - val).abs()
x = x.sort_values(col)
minn = x['diff_to_n'].min()
return x.where(x['diff_to_n'] ==minn)
s = sum_col(col, n, x)
fisrt = s[col].max()
new_n = n - s[col].max()
indexx = []
indexx.append(s[col].idxmax())
indexx
new_s = sum_col(col, new_n, x)
indexx.append(new_s[col].idxmax())
final_val = fisrt + new_s[col].max()
final_val
sorted(indexx)
 
hmmm
I try something
 
First we call sum_col function with our column, n and df. I subtract n from each row and take abs and make a new column. I find min value from that column because I have subtracted n. Select that row and I add index of that row to indexx list.
This is first pass. So I got 83434 as my first output.
then I subtract this from n which is 100000-83434
so I call that function with this new value
 
hmmm
 
1:18 PM
I hope you understand]
if not please let me know
 
Maybe I have to explain something
 
I have no IT study background
so loops solutions are not easy for me, like here
 
you are statistician?
 
still not sure if is possible avoid all combinations 3, 4 , .. 179 values and test sum :(
 
1:20 PM
like mathematician?
with my solution we don't need to try combination
Okay I will try coding it
 
no
I study telecommunication ;)
 
how do you answer pandas questions?
 
Because I answer these question for 4 years every day ;) So I lerant it ;)
 
It is my hobby ;)
 
1:23 PM
Well I will try on my end
 
ok
I try too something, but not idea now
 
 
1 hour later…
2:38 PM
it is solved
yayyy
Did it with minimum code
 

last day (15 days later) »