0

I need to assign two columns (column 2 & column 3) to exiting data frame on basis of other column present in data frame( column 1).

i tried if & else condition but not succeed.

condition is:-

for column 2 :- =IF(LEFT(D,5)="=====","BLANK",IF(LEFT(D,5)="*****","BLANK",IF(LEFT(D,5)="Check","check",IF(LEFT(D,5)="-----","BLANK",IF(D<>"",LEFT(D,(FIND("]",D,1))),"BLANK")))))

for column 1:- =IF(C="CHECK",D,IF(LEFT(C,1)="[",B))

above mention (C & D) are columns name of Column 1

MD SAJID
  • 106
  • 1
  • 8

1 Answers1

0

All the syntax you need should be in the following sample code (I didn't check I used the if else in the right order):

import numpy as np
import pandas as pd
df = pd.DataFrame([["====="], ["CHECK"], ["[TEST"]])
df.columns=['A']
df['B'] = np.where((df["A"] == "=====") | (df["A"].str.startswith('[')), "blank", "check")

See more details at:
Selecting with complex criteria from pandas.DataFrame
Python 3 Pandas Select Dataframe using Startswith + or
vectorize conditional assignment in pandas dataframe

B. Go
  • 1,436
  • 4
  • 15
  • 22