mercredi 8 août 2018

Create csv file with in python using for or if conditions

I have designed code as :

`

import csv
import numpy as np    
data = [['Diameter', 'color', 'no']]
with open('samp1.csv', 'w') as f:
    writer = csv.writer(f, delimiter=',')
    for row in data:
        writer.writerow(row)
    for i in np.arange(20,30,0.2):
        writer.writerow(i)

f.close()`

and I want to save numbers from 20-30 with increment of .2 in diameter column but its giving errors and not even saving csv file. Can some one suggest any solution. Even there are various ranges for other columns too so need the same method to work for that code

Aucun commentaire:

Enregistrer un commentaire