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