0

I want to create a new column - 'result', and in that column the value will be stored based on the condition below. my conditions is -

1-col emp is 'salaried' or 'business' & col inc is '> 10 lakh' & col flg is 'stp' then add a column result with value 'no_issue'

2-col emp is 'salaried' or 'business' & col inc '<= 10 lakh' & col flg is 'n_stp' then put 'no_issue' in result

3-col emp is 'salaried' or 'business' & col inc '> 10 lakh' & col flg is 'n_stp' then put 'issue' in result

4-col emp is 'salaried' or 'business' & col inc '<= 10 lakh' & col flg is 'stp' then put 'issue' in result

5-col emp is 'other' & col flg is 'n_stp' then put 'no issue' in result

6-col emp is 'other' & col flg is 'stp' then put 'issue' in result

This is a very complex logic, Please help me to get the desired output

my final data with added column looks like -

import pandas as pd
data = [['1', 'stp', 'salaried', '> 10 lakh', 'no_issue'],
        ['2', 'stp', 'business', '> 10 lakh', 'no_issue' ],
        ['3', 'n_stp', 'salaried', '<= 10 lakh', 'no_issue']]

df= pd.DataFrame(data, columns = ['s.no', 'flg', 'emp', 'inc', 'result'])
df


s.no    flg     emp          inc         result
1       stp     salaried    > 10 lakh    no_issue
2       stp     business    > 10 lakh    no_issue
3       n_stp   salaried    <= 10 lakh   no_issue
3
  • Please do not provide code or data within images. Please add the actual data to the question. Also, your question is missing a lot of information. What format is the data in? What format/program do you want to add an extra column? There is too much ambiguity to provide a helpful answer. Commented Oct 6, 2021 at 5:39
  • added sir, now it will be helpful, sorry for my mistakes Commented Oct 6, 2021 at 5:45
  • What's the difference between this and your other question stackoverflow.com/questions/69464036/… Commented Oct 6, 2021 at 12:40

2 Answers 2

0

is this data availabe in form of list of lists? if yes, then you can use simple if-else condition for each case and append to the end of list

Sign up to request clarification or add additional context in comments.

1 Comment

no, it is in excel,i will have to import it and create dataframe
0
import openpyxl
path= r"c:\  path of file"
work_book=openpyxl.load_workbook(path)
sheet=work_book.active
rows=sheet.max_row
columns=sheet.max_column
sheet.cell(1,columns+1).value="Result"
for i in range(2,rows):
  if (sheet.cell(i,1).value in ('salaried' , 'business') ) and (int(sheet.cell(i,3).value)>1000000) and (sheet.cell(i,4).value=='stp'):
       sheet.cell(i,5).value='no issue'
  elif #another  conditions here:
      #do something
  elif  # another  conditions here:
      # do something
      
work_book.save(path)
work_book.close()

2 Comments

i didnt get it your code, where should i put those conditions like in the income is <10 or >=10 ?
if income is at 3rd column, use sheet.cell(i,3)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.