I want a string column of location values (for example Amsterdam, London, Paris) included in my dataset that already has 2 columns with only integer values. I don't know how to include it with a for loop.
My code looks like this:
with open(output_file_path, 'w') as csvfile:
csv_writer = csv.writer(csvfile, delimiter=',', quotechar='"', quoting=csv.QUOTE_MINIMAL)
csv_writer.writerow(['timestamp', 'id', 'integercolumn1', 'integercolumn2'])
for i in range(100):
csv_writer.writerow([timestamp, 'demo-{}'.format(i), random.randint(0, 75), random.randint(4, 10), ])
The table/dataset looks now like this:
timestamp | ID | integercolumn1 | integercolumn2 |
2020-1 | 1 | 32 | 25 |
2020-1 | 2 | 45 | 14 |
But I want something like this. Thus random location also included
timestamp | ID | integercolumn1 | integercolumn2 | location
2020-1 | 1 | 32 | 25 | London
2020-1 | 2 | 45 | 14 | Paris