I am trying to implement my own function. Below you can see my code and data
import pandas as pd
import numpy as np
data = {'type_sale':[100,0,24,0,0,20,0,0,0,0],
'salary':[0,0,24,80,20,20,60,20,20,20],
}
df1 = pd.DataFrame(data, columns = ['type_sale',
'salary',])
def cal_fun(type_sale,salary):
if type_sale > 1:
new_sale = 0
elif (type_sale==0) and (salary >1):
new_sale = (np.random.choice, 10, p=[0.5,0.05]))/2 ###<-This line here
return (new_sale)
df1['new_sale']=cal_fun(type_sale,salary)
So with this function, I want to randomly select 50 percent of rows (with np.random) in the salary column. These randomly selected rows need to have zero at the same time in the column type_sale, and after that, I want to divide these values by 2.
I tried with the above function, but I am not sure that I made this thing properly. So can anybody help me with how to solve this problem?
In the end, I expect to have the table as the table is shown below.
Your ideas, please implement in the above format of function

