you don't need lambda
or apply
. stick to pandas and you're done in three steps (probably this can be done with less than that, too):
# 1 - Create DataFrame
import pandas as pd
dfDest = pd.DataFrame.from_items(dfDest)
# 2 - String parsing
cols = ['ISIN','CUSIP', 'CalTyp'] # Define Columns
dfDest[cols] = dfDest['DestSystemNote1'].str.split('|', n=-1, expand=True) # Split Strings to columns
# 3 - Replace unwanted parts of raw data
for header in cols: # look at every column and remove its header string from the data
dfDest[header] = dfDest[header].str.replace(header + "=", '') # and add "=" to pattern you want to remove
print dfDest
Output:
DestSystemNote1 ISIN CUSIP CalTyp
0 ISIN=XS1906311763|CUSIP= |CalTyp=1 XS1906311763 1
1 ISIN=XS0736418962|CUSIP= |CalTyp=1 XS0736418962 1
2 ISIN=XS1533910508|CUSIP= |CalTyp=1 XS1533910508 1
3 ISIN=US404280AS86|CUSIP=404280AS8|CalTyp=1 US404280AS86 404280AS8 1
4 ISIN=US404280BW89|CUSIP=404280BW8|CalTyp=21 US404280BW89 404280BW8 21
5 ISIN=US06738EBC84|CUSIP=06738EBC8|CalTyp=21 US06738EBC84 06738EBC8 21
6 ISIN=XS0736418962|CUSIP= |CalTyp=1 XS0736418962 1
happy coding.
manpreet
Best Answer
2 years ago
I am updating a column based on a substring in another column. This has been done by iterating through the rows.
To aid my learning, I would like to do the same thing but use the apply method with a lambda function i.e. update a third column
FOUND_ISIN2
but I'm gettingTypeError: string indices must be integers