Python Forum
Help with making a formula using variables that I have declared within for loops.
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help with making a formula using variables that I have declared within for loops.
#1
I am using python 3.8.1 and pandas.

I have two sets of data as csv files. orders.csv and vouchers.csv. Using vouchers.csv I have grouped the dataframe by 'Name' by iterating through the csv file in a for loop I can come up with a variable containing the Name, Discount1 and Discount2 (these discounts need to be applied differently that is why they are separate.

From orders.csv i also group by 'Name' and iterate through a for loop to calculate total sales and deductions. (I do this by filtering and summing columns of the csv for each sub dataframe(which is a list of orders for the 'Name').

I need to use the Discount1 and Discount2 in my final calculation. I am unsure how to get the program to recognise that if the name matches then apply this discount otherwise do not or apply 0.

Sidenotes: When I print my Discount1 and discount2 variables outside the loop it only prints the last iteration of the loop. I can get it to work by appending the variable into a list or even a nested list, however, I do not know where to go from here or whether that is the correct thing to do.

Just ask if you need more clarity anywhere I struggle to understand my issue myself let alone write it down.

Thanks in advance!
Reply
#2
It's always odd, when one try to describe what their code is doing, but don't show single line of code...
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#3
Need the code, and need you to print head() of that frame once you have it in final form
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020