I'm currently trying to write to a CSV file in python, however I only want to print 'CurrentInv' every 60 iterations. For example
outfile = open("Pension.csv", 'w')
for k in range(1,Iterations+1):
outfile.write(str( str(k) + ','))
outfile.write(str(CurrentInv[k][0])+',')
outfile.write(str(CurrentInv[k][60])+',')
outfile.write(str(CurrentInv[k][120])+',')
outfile.write(str(CurrentInv[k][180])+',')
outfile.write(str(CurrentInv[k][240])+',')
outfile.write(str(CurrentInv[k][300])+',')
outfile.write(str(CurrentInv[k][360])+',')
outfile.write(str('\n'))
outfile.close()
But I would like to obtain this in a loop. I have tried
outfile = open("Pension5.csv", 'w')
for k in range(1,Iterations+1):
outfile.write(str( str(k) + ','))
for i in range(0,Months+1):
outfile.write(str(CurrentInv[k][i])+',')
i=i+60
outfile.write(str('\n'))
outfile.close()`
However, this still prints all values for CurrentInv from 0 to Months instead of every 60 iterations. Any help would be appreciated!
range(0,Months+1,60).