I want to take first five digits from column C if there is word "US" in column B else take all the digits from column C.Required outputs are in column "OUTPUT".
A B C OUTPUT
hell US 12234455 12234
mell UK 12345666 12345666
shall US 21248075 21248
pel SPAIN 90056784 90056784
wel SP 35455689 35455689
shel US 12095678 12095
I am using the following codes but its not working.Please help.Dataset name=sf1
if sf1.B.all=="US":
sf1['OUTPUT'] = sf1['C'].astype(str).str[:5]
else:
sf1['OUTPUT'] = sf1['C'].astype(str)