I have json file contains arithmetic operation list to apply in dataframe columns, I used eval function , but i could not use eval function due to security issue, how can apply arithmetic operation from json file without using eval function my df function will be like the below table:
a | b | c | d |
---|---|---|---|
10 | 20 | 40 | 25 |
15 | 10 | 35 | 10 |
25 | 20 | 30 | 100 |
100 | 15 | 35 | 20 |
20 | 25 | 25 | 15 |
10 | 25 | 45 | 30 |
10 | 20 | 40 | 25 |
10 | 20 | 40 | 25 |
json_ops_list= {"1":"a/b",
"2":"a+b+c",
"3": "(a-b)/(b+d)",
"4":"(a-b)/(b*d+c)"}
def calculations(df, json_ops_list):
final_df = pd.DataFrame()
for i in json_ops_list:
col_name = i + '_final'
final_df[col_name] = df.eval(i)
return final_df```