I have an Excel file ... name, description, scope (column scope is fast empty)
and I want to assign a "code" (0, 1, 2 and 3) in each row of the scope column
when in the first_row 1,2 or all elements of the list l1 are also in the columns name and description
then scope.first_row = 0 and so on.
here is my code but it doesnt work
and I want to assign a "code" (0, 1, 2 and 3) in each row of the scope column
when in the first_row 1,2 or all elements of the list l1 are also in the columns name and description
then scope.first_row = 0 and so on.
here is my code but it doesnt work
from pandas import ExcelWriter import pandas as pd df2 = pd.read_excel('file.xlsx', 'sheet1', na_values=['NULL']) #df2 l1 = ["a", "b", "c"] l2 = ["d", "e", "f"] l3 = ["g", "h", "i"] l4 = ["j", "k", "l"] for ind in df2.index: for i in l1: if l1[i] in df2.index and l1[i] in df2.index: df2["Scope"] = 0 #df2 for ind in df2.index: for i in l2: if l2[i] in df2.index and l2[i] in df2.index: df2["Scope"] = 1 #df2 for ind in df2.index: for i in l3: if l3[i] in df2.index and l3[i] in df2.index: df2["Scope"] = 2 #df2 for ind in df2.index: for i in l4: if l4[i] in df2.index and l4[i] in df2.index: df2["Scope"] = 3 #df2 writer = ExcelWriter('output_file.xlsx') df2.to_excel(writer,'Sheet1',index=False) writer.save()Can someone help me with this issue ... please