-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate-location.py
42 lines (34 loc) · 1.11 KB
/
generate-location.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import argparse
import pandas as pd
from random_address import real_random_address
# use for help with cli interaction
parser = argparse.ArgumentParser(description='Generate Supply Chain Locations')
parser.add_argument('input', help='input supply chain data')
parser.add_argument('output', help='output file')
args = parser.parse_args()
# read in the csv
df = pd.read_csv(args.input)
# remove columns that are no longer needed
df.drop(columns=[
'SupplierAddress',
'City',
'Country',
'CountryCode',
'State',
'CustomerAddress',
'PostalCode',
], inplace=True, errors='ignore')
# helper function to generate locations
def generate_locations():
locations = real_random_address()
# remove unnecessary values
locations.pop('coordinates', None)
# join the address into string
return ' '.join([v for v in locations.values() if v])
# generate random addresses for the supplier and customer
df = df.assign(
SupplierAddress=[generate_locations() for _ in range(df.shape[0])],
CustomerAddress=[generate_locations() for _ in range(df.shape[0])],
)
# output to csv
df.to_csv(args.output)