Combining two column correspondingly

wannabeAIengineer :

I have imported Outlook email CSV data and dropped unnecessary columns.

    CC(Name)                           CC(Email)
  A; B; C; D; E         abc@aa; def@dd; asd@aa; wer@dd; qwer@qq
  B; F; E; R; W         def@dd; wer@aa; qwer@qq; wer@ee; wee@rr

And now I have these two columns which I initially wanted to extract together like "A<abc@aa>; B<def@aa>----" as one column.

As preprocessing, I want to put <> onto emails and make it one correspondingly. Is it technically possible by using Pandas actually..?

In my case of example,

CC(Name) column consists of objects such as

Mr.Chicken;Water;Ms.Cat;Forest;Dog

And correspondingly, CC(Email) column has exactly like

/0-org-name/ou=administrative group/cn=recipient/cn=unique num;aaa@we;/o-same-org------

Outlook export method gave me this kinda weird address because they use org account or something..

Does the "/" matter when trying to separate the str?

Chris A :

One way using list comprehension with zip, split and join:

df['output'] = ['; '.join([f'{n1}<{e1}>' for n1, e1 in zip(n.split('; '), e.split('; '))])
                for n, e in zip(df['CC(Name)'], df['CC(Email)'])]
print(df)

[out]

        CC(Name)                                CC(Email)                                                  output
0  A; B; C; D; E  abc@aa; def@dd; asd@aa; wer@dd; qwer@qq  A<abc@aa>; B<def@dd>; C<asd@aa>; D<wer@dd>; E<qwer@qq>
1  B; F; E; R; W  def@dd; wer@aa; qwer@qq; wer@ee; wee@rr  B<def@dd>; F<wer@aa>; E<qwer@qq>; R<wer@ee>; W<wee@rr>

Update

In case of float types, you can try using str():

df['output'] = ['; '.join([f'{n1}<{e1}>' for n1, e1 
                           in zip(str(n).split('; '), str(e).split('; '))])
                for n, e in zip(df['CC(Name)'], df['CC(Email)'])]

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=9513&siteId=1