1
votes

my workbook Rule.xlsx has following data.

sheet1:

 group      ordercode      quantity
     0            A             1
                  B             3
     1            C             1
                  E             2
                  D             1

Sheet 2:

group      ordercode      quantity
     0            x             1
                  y             3
     1            x             1
                  y             2
                  z             1

I have created dataframe using below method.

 df1 =data.parse('sheet1')
 df2=data.parse('sheet2')

my desired result is writing a sequence using these two dataframe.

 df3:

group      ordercode      quantity
     0            A             1
                  B             3
     0            x             1
                  y             3
     1            C             1
                  E             2
                  D             1
     1            x             1
                  y             2
                  z             1

one from df1 and one from df2.

I wish to know how I can print the data by selecting group number (eg. group(0), group(1) etc).

any suggestion ?

1

1 Answers

2
votes

After some comments solution is:

#create OrderDict of DataFrames
dfs = pd.read_excel('Rule.xlsx', sheet_name=None)
#ordering of DataFrames
order = 'SWC_1380_81,SWC_1382,SWC_1390,SWC_1391,SWM_1380_81'.split(',')

#in loops lookup dictionaries, replace NaNs and create helper column
L = [dfs[x].ffill().assign(g=i) for i, x in enumerate(order)]

#last join together, sorting and last remove helper column
df = pd.concat(L).sort_values(['group','g'])