Python Forum

Full Version: calculate the difference
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I am totally NEW.
I have a CSV file, I only have Sales, I need to calculate the amt change which is (day2 Sales) - (day1 Sales)
I need to add all the positive change and add only the negative together for the past 6 days data.

so, in the end, it would look like this:

------------------------------------------------
Output:
Sales amt change add only add only 374.440002 positive negitive 381.420013 6.980 past 6 changes 391.540009 10.120 390.75 0.790 384.73999 6.010 395.859985 11.120 391.929993 3.930 4.703333667 1.788335167 374.519989 17.410 3.5399985 4.6900025 369.040009 5.480 1.8533325 5.6033325 364.940002 4.100 1.8533325 6.154998833 370.160004 5.220 2.723332833 5.1533305 379.640015 9.480 2.450002167 5.1533305 375.459991 4.180 2.450002167 5.1950025 381.720001 6.260 3.493337167 2.293335167
----------------------------------------------------

Here is my code
counter_1=1
data['amt change']=0

if (counter_1<=40) :
    data.ix[counter_1,'amt change'] =data.ix[counter_1,'Sales']-data.ix[counter_1-1,'Sales']
    counter_1 = counter_1+1
    print(x)
    
    print(counter_1)
    
    
    
data[['amt change']].head(20)
    
    print(counter_1)
i cannot pass this point.
Please help.


I dont have a website for a picture to this one. if anyone can tell me any img uploading resources, pelase let me know.
Many thanks.
update the desired output

Output:
Sales amt change add only add only 374.440002 positive negitive 381.420013 6.980 past 6 changes 391.540009 10.120 390.75 -0.790 384.73999 -6.010 395.859985 11.120 391.929993 -3.930 4.703333667 1.788335167 374.519989 -17.410 3.5399985 4.6900025 369.040009 -5.480 1.8533325 5.6033325 364.940002 -4.100 1.8533325 6.154998833 370.160004 5.220 2.723332833 5.1533305 379.640015 9.480 2.450002167 5.1533305 375.459991 -4.180 2.450002167 5.1950025 381.720001 6.260 3.493337167 2.293335167