Iterate through Multiindex
I have a dataframe based on this data:
np.random.seed(1111)
df = pd.DataFrame({
'Category':np.random.choice( ['Group A','Group B'], 10000),
'Sub-Category':np.random.choice( ['X','Y','Z'], 10000),
'Sub-Category-2':np.random.choice( ['G','F','I'], 10000),
'Product':np.random.choice( ['Product 1','Product 2','Product 3'], 10000),
'Units_Sold':np.random.randint(1,100, size=(10000)),
'Dollars_Sold':np.random.randint(100,1000, size=10000),
'Customer':np.random.choice(pd.util.testing.rands_array(10,25,dtype='str'),10000),
'Date':np.random.choice( pd.date_range('1/1/2016','12/31/2018',
freq='D'), 10000)})
I then create a groupby to format my data as I'd like:
sales = df.groupby([df.Date.dt.month,'Customer','Product'])['Units_Sold','Dollars_Sold'].sum()
I'd like to iterate through this groupby to write each 'Customer' to it's own Excel workbook with the file being saved as 'Customer'.xlsx. Inside each workbook for each customer, I'd like to have each 'Date' (aka Month) write to it's own worksheet.
Here is an example of a loop I'm currently using to write each customer to it's own sheet:
idx = pd.IndexSlice
writer = pd.ExcelWriter('test.xlsx', engine='xlsxwriter')
for c in sales.index.get_level_values(1).unique():
sales.loc[idx[:,c,:],idx[:]]
.to_excel(writer, sheet_name=c)
writer.save()
I have found a way to write each to it's own sheet inside a workbook, but can't seem to put it all together. Thanks for your help!
python pandas
add a comment |
I have a dataframe based on this data:
np.random.seed(1111)
df = pd.DataFrame({
'Category':np.random.choice( ['Group A','Group B'], 10000),
'Sub-Category':np.random.choice( ['X','Y','Z'], 10000),
'Sub-Category-2':np.random.choice( ['G','F','I'], 10000),
'Product':np.random.choice( ['Product 1','Product 2','Product 3'], 10000),
'Units_Sold':np.random.randint(1,100, size=(10000)),
'Dollars_Sold':np.random.randint(100,1000, size=10000),
'Customer':np.random.choice(pd.util.testing.rands_array(10,25,dtype='str'),10000),
'Date':np.random.choice( pd.date_range('1/1/2016','12/31/2018',
freq='D'), 10000)})
I then create a groupby to format my data as I'd like:
sales = df.groupby([df.Date.dt.month,'Customer','Product'])['Units_Sold','Dollars_Sold'].sum()
I'd like to iterate through this groupby to write each 'Customer' to it's own Excel workbook with the file being saved as 'Customer'.xlsx. Inside each workbook for each customer, I'd like to have each 'Date' (aka Month) write to it's own worksheet.
Here is an example of a loop I'm currently using to write each customer to it's own sheet:
idx = pd.IndexSlice
writer = pd.ExcelWriter('test.xlsx', engine='xlsxwriter')
for c in sales.index.get_level_values(1).unique():
sales.loc[idx[:,c,:],idx[:]]
.to_excel(writer, sheet_name=c)
writer.save()
I have found a way to write each to it's own sheet inside a workbook, but can't seem to put it all together. Thanks for your help!
python pandas
Try making the 'Customer' the first item in your groupby list. This will make things easier.
– Chris
Dec 28 '18 at 16:49
Hi Chris - thanks for taking the time to respond. That's not an issue & is easy enough to do just by swapping the order in the groupby. I'm looking for more of the methodology behind it all as there are many examples where I'd use this type of code in the future. Thanks again for taking a look!
– keg5038
Dec 28 '18 at 16:56
add a comment |
I have a dataframe based on this data:
np.random.seed(1111)
df = pd.DataFrame({
'Category':np.random.choice( ['Group A','Group B'], 10000),
'Sub-Category':np.random.choice( ['X','Y','Z'], 10000),
'Sub-Category-2':np.random.choice( ['G','F','I'], 10000),
'Product':np.random.choice( ['Product 1','Product 2','Product 3'], 10000),
'Units_Sold':np.random.randint(1,100, size=(10000)),
'Dollars_Sold':np.random.randint(100,1000, size=10000),
'Customer':np.random.choice(pd.util.testing.rands_array(10,25,dtype='str'),10000),
'Date':np.random.choice( pd.date_range('1/1/2016','12/31/2018',
freq='D'), 10000)})
I then create a groupby to format my data as I'd like:
sales = df.groupby([df.Date.dt.month,'Customer','Product'])['Units_Sold','Dollars_Sold'].sum()
I'd like to iterate through this groupby to write each 'Customer' to it's own Excel workbook with the file being saved as 'Customer'.xlsx. Inside each workbook for each customer, I'd like to have each 'Date' (aka Month) write to it's own worksheet.
Here is an example of a loop I'm currently using to write each customer to it's own sheet:
idx = pd.IndexSlice
writer = pd.ExcelWriter('test.xlsx', engine='xlsxwriter')
for c in sales.index.get_level_values(1).unique():
sales.loc[idx[:,c,:],idx[:]]
.to_excel(writer, sheet_name=c)
writer.save()
I have found a way to write each to it's own sheet inside a workbook, but can't seem to put it all together. Thanks for your help!
python pandas
I have a dataframe based on this data:
np.random.seed(1111)
df = pd.DataFrame({
'Category':np.random.choice( ['Group A','Group B'], 10000),
'Sub-Category':np.random.choice( ['X','Y','Z'], 10000),
'Sub-Category-2':np.random.choice( ['G','F','I'], 10000),
'Product':np.random.choice( ['Product 1','Product 2','Product 3'], 10000),
'Units_Sold':np.random.randint(1,100, size=(10000)),
'Dollars_Sold':np.random.randint(100,1000, size=10000),
'Customer':np.random.choice(pd.util.testing.rands_array(10,25,dtype='str'),10000),
'Date':np.random.choice( pd.date_range('1/1/2016','12/31/2018',
freq='D'), 10000)})
I then create a groupby to format my data as I'd like:
sales = df.groupby([df.Date.dt.month,'Customer','Product'])['Units_Sold','Dollars_Sold'].sum()
I'd like to iterate through this groupby to write each 'Customer' to it's own Excel workbook with the file being saved as 'Customer'.xlsx. Inside each workbook for each customer, I'd like to have each 'Date' (aka Month) write to it's own worksheet.
Here is an example of a loop I'm currently using to write each customer to it's own sheet:
idx = pd.IndexSlice
writer = pd.ExcelWriter('test.xlsx', engine='xlsxwriter')
for c in sales.index.get_level_values(1).unique():
sales.loc[idx[:,c,:],idx[:]]
.to_excel(writer, sheet_name=c)
writer.save()
I have found a way to write each to it's own sheet inside a workbook, but can't seem to put it all together. Thanks for your help!
python pandas
python pandas
asked Dec 28 '18 at 16:31
keg5038keg5038
878
878
Try making the 'Customer' the first item in your groupby list. This will make things easier.
– Chris
Dec 28 '18 at 16:49
Hi Chris - thanks for taking the time to respond. That's not an issue & is easy enough to do just by swapping the order in the groupby. I'm looking for more of the methodology behind it all as there are many examples where I'd use this type of code in the future. Thanks again for taking a look!
– keg5038
Dec 28 '18 at 16:56
add a comment |
Try making the 'Customer' the first item in your groupby list. This will make things easier.
– Chris
Dec 28 '18 at 16:49
Hi Chris - thanks for taking the time to respond. That's not an issue & is easy enough to do just by swapping the order in the groupby. I'm looking for more of the methodology behind it all as there are many examples where I'd use this type of code in the future. Thanks again for taking a look!
– keg5038
Dec 28 '18 at 16:56
Try making the 'Customer' the first item in your groupby list. This will make things easier.
– Chris
Dec 28 '18 at 16:49
Try making the 'Customer' the first item in your groupby list. This will make things easier.
– Chris
Dec 28 '18 at 16:49
Hi Chris - thanks for taking the time to respond. That's not an issue & is easy enough to do just by swapping the order in the groupby. I'm looking for more of the methodology behind it all as there are many examples where I'd use this type of code in the future. Thanks again for taking a look!
– keg5038
Dec 28 '18 at 16:56
Hi Chris - thanks for taking the time to respond. That's not an issue & is easy enough to do just by swapping the order in the groupby. I'm looking for more of the methodology behind it all as there are many examples where I'd use this type of code in the future. Thanks again for taking a look!
– keg5038
Dec 28 '18 at 16:56
add a comment |
1 Answer
1
active
oldest
votes
This worked for me. I essentially reset the index on the sales groupby object to get a regular dataframe. Take the unique list of customers from the customer column. Iterate over the list of customers, making a dataframe for each customer.
Group that by the date, then iterate over the groupby object using d, s where d = date, and s = sales.
Use string formatting to enter the customer id as the workbook name, and use str(d) as the sheet name. Use pandas to_excel to write the sheets within the workbook and save the finished workbook at the end of each iteration of the loop.
import pandas as pd
import numpy as np
np.random.seed(1111)
df = pd.DataFrame({
'Category':np.random.choice( ['Group A','Group B'], 10000),
'Sub-Category':np.random.choice( ['X','Y','Z'], 10000),
'Sub-Category-2':np.random.choice( ['G','F','I'], 10000),
'Product':np.random.choice( ['Product 1','Product 2','Product 3'], 10000),
'Units_Sold':np.random.randint(1,100, size=(10000)),
'Dollars_Sold':np.random.randint(100,1000, size=10000),
'Customer':np.random.choice(pd.util.testing.rands_array(10,25,dtype='str'),10000),
'Date':np.random.choice( pd.date_range('1/1/2016','12/31/2018',
freq='D'), 10000)})
sales = df.groupby([df.Date.dt.month,'Customer','Product'])['Units_Sold','Dollars_Sold'].sum().reset_index()
customers = sales['Customer'].unique()
for customer in customers:
writer = pd.ExcelWriter('{}.xlsx'.format(customer), engine='xlsxwriter')
temp = sales[sales['Customer'] == customer]
temp = temp.drop(columns='Customer')
temp = temp.groupby('Date')
for d, s in temp:
s.to_excel(writer, sheet_name=str(d), index=False)
writer.save()
Thanks so much! This works exactly as I had hoped. Really appreciate the help!
– keg5038
Dec 28 '18 at 18:42
I tried this with my own data - it works great! Thanks so much. Now my dilemma is I'm looking to add in formatting using Xlsxwriter. I have many new workbooks & worksheets created & to manually format is difficult. Do you have any tips in the loop as to where to place something like 'worksheet.set_column('B:C', 20) to set the column width of columns B & C for example?
– keg5038
Jan 8 at 0:35
1
Add all of your formatting just prior to the writer.save() line.
– Chris
Jan 8 at 20:22
awesome, thanks! I was trying to add it inside the second for loop & it wasn't working as anticipated. Made it harder than it needed to be - thanks!
– keg5038
Jan 10 at 14:38
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53961523%2fiterate-through-multiindex%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
This worked for me. I essentially reset the index on the sales groupby object to get a regular dataframe. Take the unique list of customers from the customer column. Iterate over the list of customers, making a dataframe for each customer.
Group that by the date, then iterate over the groupby object using d, s where d = date, and s = sales.
Use string formatting to enter the customer id as the workbook name, and use str(d) as the sheet name. Use pandas to_excel to write the sheets within the workbook and save the finished workbook at the end of each iteration of the loop.
import pandas as pd
import numpy as np
np.random.seed(1111)
df = pd.DataFrame({
'Category':np.random.choice( ['Group A','Group B'], 10000),
'Sub-Category':np.random.choice( ['X','Y','Z'], 10000),
'Sub-Category-2':np.random.choice( ['G','F','I'], 10000),
'Product':np.random.choice( ['Product 1','Product 2','Product 3'], 10000),
'Units_Sold':np.random.randint(1,100, size=(10000)),
'Dollars_Sold':np.random.randint(100,1000, size=10000),
'Customer':np.random.choice(pd.util.testing.rands_array(10,25,dtype='str'),10000),
'Date':np.random.choice( pd.date_range('1/1/2016','12/31/2018',
freq='D'), 10000)})
sales = df.groupby([df.Date.dt.month,'Customer','Product'])['Units_Sold','Dollars_Sold'].sum().reset_index()
customers = sales['Customer'].unique()
for customer in customers:
writer = pd.ExcelWriter('{}.xlsx'.format(customer), engine='xlsxwriter')
temp = sales[sales['Customer'] == customer]
temp = temp.drop(columns='Customer')
temp = temp.groupby('Date')
for d, s in temp:
s.to_excel(writer, sheet_name=str(d), index=False)
writer.save()
Thanks so much! This works exactly as I had hoped. Really appreciate the help!
– keg5038
Dec 28 '18 at 18:42
I tried this with my own data - it works great! Thanks so much. Now my dilemma is I'm looking to add in formatting using Xlsxwriter. I have many new workbooks & worksheets created & to manually format is difficult. Do you have any tips in the loop as to where to place something like 'worksheet.set_column('B:C', 20) to set the column width of columns B & C for example?
– keg5038
Jan 8 at 0:35
1
Add all of your formatting just prior to the writer.save() line.
– Chris
Jan 8 at 20:22
awesome, thanks! I was trying to add it inside the second for loop & it wasn't working as anticipated. Made it harder than it needed to be - thanks!
– keg5038
Jan 10 at 14:38
add a comment |
This worked for me. I essentially reset the index on the sales groupby object to get a regular dataframe. Take the unique list of customers from the customer column. Iterate over the list of customers, making a dataframe for each customer.
Group that by the date, then iterate over the groupby object using d, s where d = date, and s = sales.
Use string formatting to enter the customer id as the workbook name, and use str(d) as the sheet name. Use pandas to_excel to write the sheets within the workbook and save the finished workbook at the end of each iteration of the loop.
import pandas as pd
import numpy as np
np.random.seed(1111)
df = pd.DataFrame({
'Category':np.random.choice( ['Group A','Group B'], 10000),
'Sub-Category':np.random.choice( ['X','Y','Z'], 10000),
'Sub-Category-2':np.random.choice( ['G','F','I'], 10000),
'Product':np.random.choice( ['Product 1','Product 2','Product 3'], 10000),
'Units_Sold':np.random.randint(1,100, size=(10000)),
'Dollars_Sold':np.random.randint(100,1000, size=10000),
'Customer':np.random.choice(pd.util.testing.rands_array(10,25,dtype='str'),10000),
'Date':np.random.choice( pd.date_range('1/1/2016','12/31/2018',
freq='D'), 10000)})
sales = df.groupby([df.Date.dt.month,'Customer','Product'])['Units_Sold','Dollars_Sold'].sum().reset_index()
customers = sales['Customer'].unique()
for customer in customers:
writer = pd.ExcelWriter('{}.xlsx'.format(customer), engine='xlsxwriter')
temp = sales[sales['Customer'] == customer]
temp = temp.drop(columns='Customer')
temp = temp.groupby('Date')
for d, s in temp:
s.to_excel(writer, sheet_name=str(d), index=False)
writer.save()
Thanks so much! This works exactly as I had hoped. Really appreciate the help!
– keg5038
Dec 28 '18 at 18:42
I tried this with my own data - it works great! Thanks so much. Now my dilemma is I'm looking to add in formatting using Xlsxwriter. I have many new workbooks & worksheets created & to manually format is difficult. Do you have any tips in the loop as to where to place something like 'worksheet.set_column('B:C', 20) to set the column width of columns B & C for example?
– keg5038
Jan 8 at 0:35
1
Add all of your formatting just prior to the writer.save() line.
– Chris
Jan 8 at 20:22
awesome, thanks! I was trying to add it inside the second for loop & it wasn't working as anticipated. Made it harder than it needed to be - thanks!
– keg5038
Jan 10 at 14:38
add a comment |
This worked for me. I essentially reset the index on the sales groupby object to get a regular dataframe. Take the unique list of customers from the customer column. Iterate over the list of customers, making a dataframe for each customer.
Group that by the date, then iterate over the groupby object using d, s where d = date, and s = sales.
Use string formatting to enter the customer id as the workbook name, and use str(d) as the sheet name. Use pandas to_excel to write the sheets within the workbook and save the finished workbook at the end of each iteration of the loop.
import pandas as pd
import numpy as np
np.random.seed(1111)
df = pd.DataFrame({
'Category':np.random.choice( ['Group A','Group B'], 10000),
'Sub-Category':np.random.choice( ['X','Y','Z'], 10000),
'Sub-Category-2':np.random.choice( ['G','F','I'], 10000),
'Product':np.random.choice( ['Product 1','Product 2','Product 3'], 10000),
'Units_Sold':np.random.randint(1,100, size=(10000)),
'Dollars_Sold':np.random.randint(100,1000, size=10000),
'Customer':np.random.choice(pd.util.testing.rands_array(10,25,dtype='str'),10000),
'Date':np.random.choice( pd.date_range('1/1/2016','12/31/2018',
freq='D'), 10000)})
sales = df.groupby([df.Date.dt.month,'Customer','Product'])['Units_Sold','Dollars_Sold'].sum().reset_index()
customers = sales['Customer'].unique()
for customer in customers:
writer = pd.ExcelWriter('{}.xlsx'.format(customer), engine='xlsxwriter')
temp = sales[sales['Customer'] == customer]
temp = temp.drop(columns='Customer')
temp = temp.groupby('Date')
for d, s in temp:
s.to_excel(writer, sheet_name=str(d), index=False)
writer.save()
This worked for me. I essentially reset the index on the sales groupby object to get a regular dataframe. Take the unique list of customers from the customer column. Iterate over the list of customers, making a dataframe for each customer.
Group that by the date, then iterate over the groupby object using d, s where d = date, and s = sales.
Use string formatting to enter the customer id as the workbook name, and use str(d) as the sheet name. Use pandas to_excel to write the sheets within the workbook and save the finished workbook at the end of each iteration of the loop.
import pandas as pd
import numpy as np
np.random.seed(1111)
df = pd.DataFrame({
'Category':np.random.choice( ['Group A','Group B'], 10000),
'Sub-Category':np.random.choice( ['X','Y','Z'], 10000),
'Sub-Category-2':np.random.choice( ['G','F','I'], 10000),
'Product':np.random.choice( ['Product 1','Product 2','Product 3'], 10000),
'Units_Sold':np.random.randint(1,100, size=(10000)),
'Dollars_Sold':np.random.randint(100,1000, size=10000),
'Customer':np.random.choice(pd.util.testing.rands_array(10,25,dtype='str'),10000),
'Date':np.random.choice( pd.date_range('1/1/2016','12/31/2018',
freq='D'), 10000)})
sales = df.groupby([df.Date.dt.month,'Customer','Product'])['Units_Sold','Dollars_Sold'].sum().reset_index()
customers = sales['Customer'].unique()
for customer in customers:
writer = pd.ExcelWriter('{}.xlsx'.format(customer), engine='xlsxwriter')
temp = sales[sales['Customer'] == customer]
temp = temp.drop(columns='Customer')
temp = temp.groupby('Date')
for d, s in temp:
s.to_excel(writer, sheet_name=str(d), index=False)
writer.save()
answered Dec 28 '18 at 17:25
ChrisChris
881515
881515
Thanks so much! This works exactly as I had hoped. Really appreciate the help!
– keg5038
Dec 28 '18 at 18:42
I tried this with my own data - it works great! Thanks so much. Now my dilemma is I'm looking to add in formatting using Xlsxwriter. I have many new workbooks & worksheets created & to manually format is difficult. Do you have any tips in the loop as to where to place something like 'worksheet.set_column('B:C', 20) to set the column width of columns B & C for example?
– keg5038
Jan 8 at 0:35
1
Add all of your formatting just prior to the writer.save() line.
– Chris
Jan 8 at 20:22
awesome, thanks! I was trying to add it inside the second for loop & it wasn't working as anticipated. Made it harder than it needed to be - thanks!
– keg5038
Jan 10 at 14:38
add a comment |
Thanks so much! This works exactly as I had hoped. Really appreciate the help!
– keg5038
Dec 28 '18 at 18:42
I tried this with my own data - it works great! Thanks so much. Now my dilemma is I'm looking to add in formatting using Xlsxwriter. I have many new workbooks & worksheets created & to manually format is difficult. Do you have any tips in the loop as to where to place something like 'worksheet.set_column('B:C', 20) to set the column width of columns B & C for example?
– keg5038
Jan 8 at 0:35
1
Add all of your formatting just prior to the writer.save() line.
– Chris
Jan 8 at 20:22
awesome, thanks! I was trying to add it inside the second for loop & it wasn't working as anticipated. Made it harder than it needed to be - thanks!
– keg5038
Jan 10 at 14:38
Thanks so much! This works exactly as I had hoped. Really appreciate the help!
– keg5038
Dec 28 '18 at 18:42
Thanks so much! This works exactly as I had hoped. Really appreciate the help!
– keg5038
Dec 28 '18 at 18:42
I tried this with my own data - it works great! Thanks so much. Now my dilemma is I'm looking to add in formatting using Xlsxwriter. I have many new workbooks & worksheets created & to manually format is difficult. Do you have any tips in the loop as to where to place something like 'worksheet.set_column('B:C', 20) to set the column width of columns B & C for example?
– keg5038
Jan 8 at 0:35
I tried this with my own data - it works great! Thanks so much. Now my dilemma is I'm looking to add in formatting using Xlsxwriter. I have many new workbooks & worksheets created & to manually format is difficult. Do you have any tips in the loop as to where to place something like 'worksheet.set_column('B:C', 20) to set the column width of columns B & C for example?
– keg5038
Jan 8 at 0:35
1
1
Add all of your formatting just prior to the writer.save() line.
– Chris
Jan 8 at 20:22
Add all of your formatting just prior to the writer.save() line.
– Chris
Jan 8 at 20:22
awesome, thanks! I was trying to add it inside the second for loop & it wasn't working as anticipated. Made it harder than it needed to be - thanks!
– keg5038
Jan 10 at 14:38
awesome, thanks! I was trying to add it inside the second for loop & it wasn't working as anticipated. Made it harder than it needed to be - thanks!
– keg5038
Jan 10 at 14:38
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53961523%2fiterate-through-multiindex%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Try making the 'Customer' the first item in your groupby list. This will make things easier.
– Chris
Dec 28 '18 at 16:49
Hi Chris - thanks for taking the time to respond. That's not an issue & is easy enough to do just by swapping the order in the groupby. I'm looking for more of the methodology behind it all as there are many examples where I'd use this type of code in the future. Thanks again for taking a look!
– keg5038
Dec 28 '18 at 16:56