I have the following dataframe and I need to do the following:
-subtract the free package limit from the total number of calls
-multiply the result by the calling plan value
-add the monthly charge depending on the calling plan
There are 2 plan types:
Surf: Monthly charge: $20, 500 monthly minutes
-After exceeding the limits:1 minute: 3 cents
Ultimate: Monthly charge: $70, 3000 monthly minutes
-After exceeding the limits: 1 minute: 1 cent
Here is the function I tried to make and tried to apply it to a new column: https://pastebin.com/iB3GwrQ9
def extra_cost(row):
calls = row['min_1', 'min_2', 'min_3', 'min_4', 'min_5', 'min_6', 'min_7', 'min_8', 'min_9', 'min_10', 'min_11', 'min_12']
if plan_name == 'surf':
if calls > 500:
return (calls - 500)
else:
return "NaN"
if plane_name == 'ultimate':
if calls > 3000:
return (calls - 3000)
else:
return "NaN"
else:
return "NaN"
user_calls1['sum'] = user_calls1.apply(extra_cost(row))
Here is the dataframe head: https://pastebin.com/8HJWbgUr
user_id first_name last_name plan_name min_1 min_2 min_3 min_4 min_5 \
1000 Anamaria Bauer ultimate NaN NaN NaN NaN NaN
1001 Mickey Wilkerson surf NaN NaN NaN NaN NaN
1002 Carlee Hoffman surf NaN NaN NaN NaN NaN
1003 Reynaldo Jenkins surf NaN NaN NaN NaN NaN
1004 Leonila Thompson surf NaN NaN NaN NaN 181.58
user_id first_name last_name plan_name min_6 min_7 min_8 min_9 \
1000 Anamaria Bauer ultimate NaN NaN NaN NaN
1001 Mickey Wilkerson surf NaN NaN 171.14 297.69
1002 Carlee Hoffman surf NaN NaN NaN NaN
1003 Reynaldo Jenkins surf NaN NaN NaN NaN
1004 Leonila Thompson surf 261.32 358.45 334.86 284.60
user_id first_name last_name plan_name min_10 min_11 min_12
1000 Anamaria Bauer ultimate NaN NaN 116.83
1001 Mickey Wilkerson surf 374.11 404.59 392.93
1002 Carlee Hoffman surf 54.13 359.76 363.24
1003 Reynaldo Jenkins surf NaN NaN 1041.00
1004 Leonila Thompson surf 341.63 452.98 403.53
I have not been able to figure out why it is not working and returning " name 'row' is not defined ". If there is a better solution, please let me know!