0

I have a Pandas Dataframe as follows:

dic = {
    'Name': ['Alsa','Jaguar','Lima','Panda','Foxtron','India'],
    'x'   : ['2233','1200'  ,'0341','2332' ,'1321'   ,'0445' ],
    'y'   : ['321' ,'231'   ,'440' ,'210'  ,'110'    ,'500'  ]
}

df = pd.DataFrame(dic)
df
    Name     x       y
0   Alsa    2233    321
1   Jaguar  1200    231
2   Lima    0341    440
3   Panda   2332    210
4   Foxtron 1321    110
5   India   0445    500

I have another Pandas Series as follows:

s
0       Alsa
0     Jaguar
0      Panda
0      India
1      Panda
1    Foxtron
2      India
2     Jaguar
2       Alsa

I need to locate the Pandas Series (s) in the Pandas Dataframe (df) and return the corresponding x and y. The expected result would be:

0       Alsa    2233    321
0     Jaguar    1200    231
0      Panda    2332    210
0      India    0445    500
1      Panda    2332    210
1    Foxtron    1321    110
2      India    0445    500
2     Jaguar    1200    231
2       Alsa    2233    321

One method is to use apply. However the data that I have is really huge and apply will be very slow. I'm looking for other solutions.

Note: Pandas Series include repeated values and I require them to be repeated, e.g. Alsa is repeated twice.

Ali Sultan
  • 280
  • 1
  • 16

0 Answers0