0

I have a DF like this:

ID Name Mail Phone1 Phone2 Mail1 Mail2 contact phone contact mail
70 DASS ARGENTINA SRL info@iricresanluis.com.ar 2664941642 2664941644 info@iricresanluis.com.ar info_tec@iricresanluis.com.ar 115456789 contact_mail@gmail.com
71 PEPSI mail_general@pepsi.com 0456535365 7766554399 mail1@pepsi.com mail2@pepsi.com 8864545332 last_mail@pepsi.com
ID Name LOCATOR
70 DASS ARGENTINA SRL info@iricresanluis.com.ar
70 DASS ARGENTINA SRL 2664941642
70 DASS ARGENTINA SRL 2664941644
70 DASS ARGENTINA SRL info@iricresanluis.com.ar
70 DASS ARGENTINA SRL info_tec@iricresanluis.com.ar
70 DASS ARGENTINA SRL 115456789
70 DASS ARGENTINA SRL contact_mail@gmail.com
71 PEPSI mail_general@pepsi.com
71 PEPSI 0456535365
71 PEPSI 7766554399
71 PEPSI mail1@pepsi.com
71 PEPSI mail2@pepsi.com
71 PEPSI 8864545332
71 PEPSI last_mail@pepsi.com

Is it possible to do anythong like this? I´ve tried with transpose function but I´m not getting the output like the example above

Maximiliano Vazquez
  • 196
  • 1
  • 2
  • 12

1 Answers1

1

use pd.melt to flatten the dataframe and then sort and remove the unwanted columns

df.drop(columns='ID').melt(id_vars='Name', value_name='Locator').sort_values('Name').drop(columns='variable')
                  Name  Locator
0   DASS ARGENTINA SRL  info@iricresanluis.com.ar
2   DASS ARGENTINA SRL  2664941642
4   DASS ARGENTINA SRL  2664941644
6   DASS ARGENTINA SRL  info@iricresanluis.com.ar
8   DASS ARGENTINA SRL  info_tec@iricresanluis.com.ar
10  DASS ARGENTINA SRL  115456789
12  DASS ARGENTINA SRL  contact_mail@gmail.com
1   PEPSI               mail_general@pepsi.com
3   PEPSI               456535365
5   PEPSI               7766554399
7   PEPSI               mail1@pepsi.com
9   PEPSI               mail2@pepsi.com
11  PEPSI               8864545332
13  PEPSI               last_mail@pepsi.com
Naveed
  • 11,495
  • 2
  • 14
  • 21