创建的DataFrame似乎仅被冻结为3个索引

时间:2019-02-15 09:43:03

标签: python pandas

运行我的代码后,名为“ General_Adj”(调整表)的数据框无法加载整个输入数据。

我正在开发一个程序来简化日常工作流程,我们总是必须从销售代表处收集销售订单信息,以便在每个季度末调整其效果。

我已经完成了零件数据收集,这是一个由订单号,SKU号,最终用户号和经销商信息列组成的收集表,另一个模块已经完成,是订单分类,这对订单调整并不重要,这就是我遇到的问题所在。

当订单流到该模块时,首先将其定义为拆分订单或非拆分订单。对于NON-SPLIT订单(由于只有1个最终用户,因此在我们的收集表中仅需要1行),应将其记录为从经销商处“删除”,然后将其“添加”到最终用户,并且将有两条记录记为数据框“常规调整”。当订单为SPLIT订单(两个或更多行且有多个最终用户)时,第一行仍从经销商处“删除”,然后应记下多个最终用户信息,因此在“常规调整”中,此拆分订单将拥有更多行数取决于最终用户数。

在我的情况下,我有1个非拆分订单和1个拆分订单以及2个最终用户。这意味着在“ General Adj”中,总共应该有5条记录,但是,当我在下面运行我的代码时,它仅显示3行。我曾尝试过多次以解决此问题,但失败了。请帮助解决这个问题,谢谢!

i = 0
j = 0
z = 0
x = 0
for i in range(Cur_Q_with_Comments.index.max()+1) or j in range(Cur_Q_with_Comments['Count'].sum()+1):
    if i == (Cur_Q_with_Comments.index.max()+1):
        break
    elif ("SPLIT" not in Cur_Q_with_Comments['Comments'].loc[i]) & (Cur_Q_with_Comments['Count'].iloc[i] == 1):
        print("One Record was loaded in General non-split workflow")
        for x in range(2):
            print(x)
            if x == 0:
                General_Adj['Adj Type'] = 'PRE_ADJ'
                General_Adj['Fiscal Year'] = Cur_Q_with_Comments['Fiscal Year']
                General_Adj['Fiscal Quarter'] = Cur_Q_with_Comments['Fiscal Quarter']
                print("Writing Down Dealer info")
                General_Adj['Original Order Number'].loc[j] = Cur_Q_with_Comments['LSG Order number'].loc[i]
                General_Adj['Original SKU Number'].loc[j] = Cur_Q_with_Comments['SKU number'].loc[i]
                General_Adj['Adj Mode'].loc[j] = 'REMOVE'
            elif x > 0:
                General_Adj['Adj Type'] = 'PRE_ADJ'
                General_Adj['Fiscal Year'] = Cur_Q_with_Comments['Fiscal Year'].loc[i]
                General_Adj['Fiscal Quarter'] = Cur_Q_with_Comments['Fiscal Quarter'].loc[i]
                print("Writing Down End Users info")
                General_Adj['Original Order Number'].loc[j+x] = Cur_Q_with_Comments['LSG Order number'].loc[i]
                General_Adj['Original SKU Number'].loc[j+x] = Cur_Q_with_Comments['SKU number'].loc[i]
                General_Adj['Adj Mode'].loc[j+x] =  'ADD'
                General_Adj['EndUserSGNID'].loc[j+x] = Cur_Q_with_Comments['End user SGN#'].loc[i]
                General_Adj['End User SGN Name'].loc[j+x] = Cur_Q_with_Comments['End user name'].loc[i]
                print("Non-Split Info:",General_Adj)
        i = i+1
        j = x+j+1
        print("Non-Split Integration:",i,j)


    elif ("SPLIT" in Cur_Q_with_Comments['Comments'].loc[i]) | (Cur_Q_with_Comments['Count'].iloc[i] >= 1):
        for z in range(Cur_Q_with_Comments['Count'].loc[i]+1):
            if z == 0:
                General_Adj['Adj Type'] = 'PRE_ADJ'
                General_Adj['Fiscal Year'] = Cur_Q_with_Comments['Fiscal Year']
                General_Adj['Fiscal Quarter'] = Cur_Q_with_Comments['Fiscal Quarter']
                General_Adj['Adj Category'].loc[j] = 'SPLIT'
                General_Adj['Adj Mode'].loc[j] = 'REMOVE'
                General_Adj['Original Order Number'].loc[j] = Cur_Q_with_Comments['LSG Order Number'].loc[i]
                General_Adj['Original SKU Number'].loc[j] = Cur_Q_with_Comments['SKU Number'].loc[i]
                General_Adj['Quantity'].loc[j] = -(Cur_Q_with_Comments['Actual Units'].loc[i])
                General_Adj['Amount'].loc[j] = -(Cur_Q_with_Comments['Actual P$'].loc[i])
            elif z > 0:
                General_Adj['Adj Type'] = 'PRE_ADJ'
                General_Adj['Fiscal Year'] = Cur_Q_with_Comments['Fiscal Year']
                General_Adj['Fiscal Quarter'] = Cur_Q_with_Comments['Fiscal Quarter']
                General_Adj['Adj Category'].loc[j+z] = 'SPLIT'
                General_Adj['Adj Mode'].loc[j+z] = 'ADD'
                General_Adj['Original Order Number'].loc[j+z] = Cur_Q_with_Comments['LSG Order Number'].loc[i+z-1]
                General_Adj['Original SKU Number'].loc[j+z] = Cur_Q_with_Comments['SKU Number'].loc[i+z-1]
                General_Adj['EndUserSGNID'].loc[j+z] = Cur_Q_with_Comments['End user SGN#'].loc[i+z-1]
                General_Adj['End User SGN Name'].loc[j+z] = Cur_Q_with_Comments['End user name'].loc[i+z-1]
                General_Adj['Quantity'].loc[j+z] = Cur_Q_with_Comments['Unit_x'].loc[i+z-1]
                General_Adj['Amount'].loc[j+z] = Cur_Q_with_Comments['Total Amounts'].loc[i+z-1]
        print("Split Info:",General_Adj)
        j = j+z+1
        i = i+z
        print("Split Integration:",i,j)

0 个答案:

没有答案