0

I have a Dataframe containing some Ids, here for example the "manufacturers_id". Below a portion of my dataframe

enter image description here

With an api request, I am able to get the Manufacturer from the Id. My function looks like below:

def get_manufacturer(m_id):
    url = "myapi/" + m_id + "?token=my_token"
    response = requests.get(url)
    manufacturer = json.loads(response.text)['name']
    return manufacturer

Used individually, I can retrieve manufacturer from an Id.

But now, I want to apply this function to the whole column of my dataframe.

df['manufacturers_id'] = df['manufacturers_id'].apply(get_manufacturer(df['manufacturers_id']))

But It give me an error: str is not callable. Or list indices must be integers or slices, not str, depending on my tries

Any help would be appreciated.

Tom Ron
  • 5,322
  • 2
  • 16
  • 32
Neandril
  • 102
  • 8

1 Answers1

3

Try

df['manufacturers_id'] = df['manufacturers_id'].apply(get_manufacturer)

Since the apply function used after a pandas Series indicates that entering each observation value into the function given in apply().

timgeb
  • 73,231
  • 20
  • 109
  • 138
Denny Chen
  • 424
  • 2
  • 7