create multiple columns with df.apply that uses multi return function

76 views Asked by At

I am creating a new column with df.apply and a function and would like to use the same function to create another column in the dataframe. The function returns several values from which I'm selecting one successfully. To avoid new calculation I would like to get two return outputs and create two columns in the dataframe.

df_RoadSegments["NewTime"] = df_RoadSegments.apply(lambda x: getrouteinfo(x["OriginCoordinates"], x["DestCoordinates"])[8], axis=1)

but I would like to have something like below, is it possible?

df_RoadSegments["NewTime"]["link"] = df_RoadSegments.apply(lambda x: getrouteinfo(x["OriginCoordinates"], x["DestCoordinates"])[8][9], axis=1)
0

There are 0 answers