Bottom Page

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!
Quote
#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

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

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Permutation + Formula Execution hds4ifc 2 389 Jan-02-2020, 12:32 PM
Last Post: sandeep_ganga
  Formula works for one row does not for two Prometheus 4 2,207 Aug-26-2019, 05:19 AM
Last Post: ThomasL
  Luhn Formula vdv34czx 3 1,311 May-17-2018, 08:05 AM
Last Post: buran

Forum Jump:


Users browsing this thread: 1 Guest(s)