-
-
Save buhtz/4348522b65844293518f3a4b9d69fe0b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def write_data_to_csv(data): | |
""" | |
Write the previously generate data to a csv file. | |
""" | |
time_string = datetime.datetime.now().strftime('%Y%h%d_%H%M') | |
csv_name = f'{time_string}_for_spss-import.sim.csv' | |
with open(csv_name, 'w', encoding='utf-8', newline='') as csvfile: | |
# CSV writer instance | |
writer = csv.writer(csvfile, quoting=csv.QUOTE_NONNUMERIC, | |
delimiter=';', | |
quotechar='"') | |
# headline with column names | |
writer.writerow(col_names) | |
print(f'Number of fields in headline: {len(col_names)}') | |
print(f'Number of cases: {len(data)}') | |
#writer.writerows(data) | |
for d in data: | |
print(f'{len(d)}: {d}') | |
writer.writerow(d) | |
print(f'Data written to {csv_name} and simulation.csv.') | |
shutil.copy(csv_name, 'simulation.csv') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment