Question
PYTHON QUESTION: I'm trying to write the output of this code to a .csv file in order to generate an Excel graph of the values
PYTHON QUESTION: I'm trying to write the output of this code to a .csv file in order to generate an Excel graph of the values but it won't work. How can I properly write the output to a .csv file? CODE: from timeit import Timer
popzero = Timer("x.pop(0)","from __main__ import x") popend = Timer("x.pop()","from __main__ import x") print("pop(0) pop()")
for i in range(1000000, 20000001, 1000000): x = list(range(i)) pt = popend.timeit(number = 1000) x = list(range(i)) pz = popzero.timeit(number = 1000) print("%15.5f, %15.5f" % (pz,pt))
file = open("times.csv", "w") file.write("%d, %f" % (pz, pt)) file.close() OUTPUT: pop(0) pop() 0.11478, 0.00022 0.46881, 0.00007 0.80180, 0.00010 1.14336, 0.00007 1.48661, 0.00008 1.84509, 0.00007 2.16916, 0.00007 2.49128, 0.00007 2.84637, 0.00007 3.22048, 0.00007 3.51699, 0.00007 3.83267, 0.00007 4.23944, 0.00007 4.51622, 0.00007 4.81569, 0.00007 5.15730, 0.00007 5.48136, 0.00007 5.82272, 0.00007 6.12293, 0.00010 6.48140, 0.00007
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started