Assume that I am using a client computer that will not allow for pip or pandas and must use Python 2.7. Binaries and converting into an exe is not allowed. I am reading in a CSV with column headers as names with numpy.
In my dataset, I am attempting to generate a list of orders that apply to unique combinations of Facility, Destination, Program #, and other factors, where p is the read csv dataset.
What it would look like if I did this in Excel. The values in the Order field are what I'd like to have as a list in a variable called my_orders.
My current code looks like:
progs = np.unique(p['Program'])
facil = np.unique(p['Facility'])
dest = np.unique(p['Destination'])
reqs = np.unique(p['Requested'])
prods = np.unique(p['Produced'])
tier1 = np.unique(p['Tier1'])
tier2 = np.unique(p['Tier2'])
Which is followed by the following method originally written with pandas and Python3 in mind until discovering that only 2.7 and numpy were available:
for a in range(len(progs)):
print("on Program ",a)
ProgChild = {"name":progs[a], 'children':[]}
for r in range(len(reqs)):
reqChild = {"name":reqs[r], 'children':[]}
for s in range(len(prods)):
prodChild = {'name':prods[s], "children":[]}
for g in range(len(progs)):
programChild = {'name':progs[g], "children":[]}
for i in range(len(facil)):
FacilChild={"name":facil[i], "children":[]}
for c in range(len(tier1)):
Tier1Child={"name":tier1[c], "children":[]}
for d in range(len(tier2)):
# here's where I'm in trouble:
Order_Cond = np.array[[progs[a]& reqs[r]&
prods[s]&progs[g]& facil[i]& tier1[c]]
my_orders = np.where(p['Orders'], Order_cond)
print my_orders
# do other things
As you can see the original intent was to use the For loops to set up a routine that only returned a list of Orders that came from unique combinations of facility, destination, program, etc. The Order_cond variable obviously has the wrong syntax.
If this were in SQL I'd just say "Select Orders From My_Data Where progs=a & reqs=r;" and so on.
I also considered a list comprehension but it doesn't work yet either:
list(x for p['Orders'] in p if p['Orders'] in Order_cond)
Again, the goal is for a list of Orders to be created and stored in my_orders, which I then use for other functions.