'How to return a DataFrame when using pandas.apply()

I'm trying to get a concated DataFrame using pandas.apply(), there is a demo below:

enter image description here

Just like the code shown, the apply() returns a Series instead of a concated DataFrame that I expected, how can I solve it?



Solution 1:[1]

Have you tried using df.applymap()? Tecnically, they do the same thing but the applymap apply your function to the entire Dataframe and it returns a Dataframe no matter what happens.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 rapha