2021-12-11

Tech Programing

程式人小天地

Creating a new list from the data in the list with certain rules

1 min read


I have data from different csv files. These data are listed and include VAT 0 and total amounts. Apart from these two information, many other values are also present in my list. In the example, my total amount is 4000 and VAT is 0. According to my algorithm, it replaces 4000 with the largest and possibly irrelevant value. df=[26300.0, 17360.0, 4000.0, 4000.0, 4000.0, 4000.0, 6.575, 3.7, 0.0, 0.0, 0.0] The important point is that the lists vary. Example from my shared list unittest.

def zero_vat(df):
    catch_list=[]
    df.sort(reverse = True)
    print(df)
    for i, value in enumerate(df):  # 1.array
        for j, value2 in enumerate(df):  # 2.array
            if df[i]==0:
                if df[i]+max(df)==df[j]:
                    temp_list=[]
                    temp_list.append(df[i])
                    temp_list.append(df[j])
                    temp_list.append(max(df))
                    catch_list.append(temp_list)
                    print(catch_list)
            elif df[i]+0 == max(df):
                temp_list=[]
                temp_list.append(df[i])
                temp_list.append(0.0)
                temp_list.append(max(df))
                catch_list.append(temp_list)
                print(catch_list)
            return catch_list

output : [[26300.0, 0.0, 26300.0]]
must be :[[4000.0,0.0,4.000]]



Source link

資料來源:Stackoverflow

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *