So,here I want to take first 3 character(only alphabets/no) from column 1 and first 4 character(only alphabets/no) from column 2 and first 5 digits from column3a,column3b,column3c and column3d(whichever is present) and make an array of them like in desired output column given below.Condition is that I need to remove any kind of special characters like .,-,' etc and spaces and take only alphabetical and numerical characters.Also output should be NaN if any one of column1,2 or 3 is not present.(If both 1 and 2 present and 1 from column 3 is present then output should come.
Column1 Column2 Colum3a Colum3b Colum3c Colum3d S.NO DESIRED OUTPUT
ABCDE QWERTY 12345678 1223456 234567 1234589 1
T.BCDF W ERTY 567890 NaN NaN NaN 2
ERTYUMH TY-IOPU 9845366 5672341 NaN NaN 3
NaN ERTYUI 1986788 NaN NaN NaN 4
SA--RTYUNK QWPOIJH NaN NaN 34564557 NaN 5
WQER QWER NaN NaN NaN NaN 6
S'E WERTER 12233412 NaN NaN 5678908 7
Desired output column should be like:
DESIRED OUTPUT S.NO
["ABC|QWER|12345","ABC|QWER|12234","ABC|QWER|23456","ABC|QWER|12345"] 1
[TBC|WER|56789] 2
["ERT|TYIO|98453","ERT|TYIO|56723"] 3
NaN 4
[SAR|QWPO|34564] 5
NaN 6
["SE|WERT|12233","SE|WERT|56789"] 7
Please help me with this.I m concatenating using below codes but don't know how to make array with 3rd columns.
df1['column4'] = (df1['Column1'].str[:3] + '|' +
df1['Column2'].str[:4] + '|' +
df1['Column3'].astype(str).replace({'^nan$':None, '\.0$':''}, regex=True))