I am new with python.
I have a loop with lime function which generate an output at each iteration :
file = []
res = output.as_list() at i=0 It contains [('ft-1822 > 0.45', -0.1625), ('ft-1818 > 0.18', -0.109)]
file.append(res)
res = output.as_list() at i=1 It contains [('ft-1822 > 0.45', -0.1658), ('ft-1818 > 0.18', -0.1118)]
file.append(res)
res = output.as_list() at i=2 It contains [('ft-1822 > 0.45', -0.15975), ('ft-1818 > 0.18', -0.111309)]
file.append(res)
The final file contains:
[[('ft-1822 > 0.45', -0.1625), ('ft-1818 > 0.18', -0.109)], [('ft-1822 > 0.45', -0.1658), ('ft-1818 > 0.18', -0.1118)], [('ft-1822 > 0.45', -0.15975), ('ft-1818 > 0.18', -0.111309)]]
I want to save it in an csv file with 2 columns and 3 rows :
[('ft-1822 > 0.45', -0.1625), ('ft-1818 > 0.18', -0.109)]
[('ft-1822 > 0.45', -0.1658), ('ft-1818 > 0.18', -0.1118)]
[('ft-1822 > 0.45', -0.15975), ('ft-1818 > 0.18', -0.111309)]
I tried this but I am getting all value in one row
with open('file.csv', 'w') as f:
wr = csv.writer(f, delimiter=',', quotechar='"', quoting=csv.QUOTE_MINIMAL)
wr.writerow(file)
file- minimal reproducible example pleasefile? It would probably be easier to fix the problem there, by creating a (three-element) ist of (two-element) lists, rather than a single 6-element list.