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.
我认为您需要按列中的标量apply
axis=1
应用于过程数据:
df["c"] = df.apply(lambda x: Class(x["id"]).getData(x["a"], x["b"]), axis=1)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.