123456789101112131415161718192021 |
- def state():
- if not os.path.exists('analytics'):
- os.mkdir('analytics')
- if os.path.exists('analytics/state'):
- shutil.rmtree('analytics/state')
- with open('studentinfo_cs384.csv', newline='') as csvfile:
- reader = csv.DictReader(csvfile)
- if not os.path.exists('analytics/state'):
- os.mkdir('analytics/state')
- for row in reader:
- l = list(row.values())
- head = list(row.keys())
- with open('analytics/state/'+row['state'].lower()+ '.csv', mode = 'a') as f:
- f_write = csv.writer(f, delimiter=',',lineterminator='\r')
- if os.path.getsize('analytics/state/'+row['state'].lower() + '.csv')==0:
- f_write.writerow(head)
- f_write.writerow(l)
- f.close()
- csvfile.close()
|