1

I have a class DataImporter with a method called getData that I want to apply on a pandas dataframe. The problem: the class / method can just handle single elements.

Imagine I have a DataFrame with three columns id, a and b.

What I actually want to do is something like: (pseudo code)

df["c"] = Class(df["id"]).getData(df["a"], df["b"])

I found out there is something like pandas.Series.apply, but I don't see that it works for the getData part.

1 Answer 1

2

I think you need apply with axis=1 for process data by scalars in columns:

df["c"] = df.apply(lambda x: Class(x["id"]).getData(x["a"], x["b"]), axis=1)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.