Here's a Python question:
Hello I'm making a web app, its receives the data from a spreadsheet(.csv) turning them into integers from. Evaluating those values, returning those values and writing that data to the 4'th column of the sheet, for each row. As you can see in my code:
import fileinput
import csv
import pyexcel as pe
records = pe.iget_records(file_name="test.xlxs")
cho = raw_input("\nStart Forecaster on file?:<1/0>")
if cho == 1:
for record in records:
rem = record[i,0]
sold1 = record[i,1]
sold2 = record[i,2]
rem = int(rem)
sold1 = int(sold1)
sold2 = int(sold2)
result = forecast(rem,sold1,sold2)
record[i,4] = result
print "Forecast Complete! Please check the file!"
else:
quit()
def calculate(rem,sold1,sold2):
result = ((l+t)/2)*3
return result
def forecast(rem,sold1,sold2):
if (rmn == 0 and sold1 == 0 and sold2 ==0): #All ZERO
return 15
elif (rmn == 0 and sold1 == 0 and sold2 < 10): #ALL FOR ONE PRODUCT VALUE
return sold2*3
elif (rmn == 0 and sold1 < 10 and sold2 ==0):
return sold1*3
elif (rmn < 10 and sold1 == 0 and sold2 == 0):
return rmn*3
#END FOR ONE PRODUCT VALUE
elif (rmn>= 10 and sold1>=10 and sold2>=10):
if((rmn/3)>=(sold1+10) or (rmn/3)>=(sold1+10)):
return 0
else:
return calculate(rmn,sold1,sold2)-rmn
elif (rmn<10 and sold1<10 and sold2<10):
return calculate(rmn,sold1,sold2)
elif (rmn == 0 and sold1>=10 and sold2>=10):
return calculate(rmn,sold1,sold2)
else:
return sold1
... There were no errors but it didnt have any effect on the csv file. Any ideas? Also at print "Forecast Complete! Please check the file!" .. when i run the program it doesn't get there which means there has to be something wrong with the looping? I'm figuring it out right now. But I want to ask for help as well.
Original file:
1 2 3
1 2 3
1 2 3
What I wanted to happen:
1 2 3 result(digits)
1 2 3 result(digits)
1 2 3 result(digits)
records = pe.iget_records(file_name="test.xlxs")is just pulling the file contents into Python, where you manipulate it and then throw the results away. Have a look at the tutorial on writing/saving changes.records.save_as("test.xlsx")but still it doesn't work, how do you see my loop? is there something wrong with it?printof the data before saving that you have actually calculated the things you think you have.pandas,openpyxl,orxlsxwritermodules instead ofpyexcel?