Skip to content
Advertisement

How to efficiently combine multiple pandas columns into one array-like column?

It is easy to create (or load) a DataFrame with something like an object-typed column, as so:

JavaScript

I am currently in the position where I have, as separate columns, values that I am required to return as a single column, and need to do so quite efficiently. Is there a fast and efficient way to combine columns into a single object-type column?

In the example above, this would mean already having columns a, b, and c, and I wish to create combined.

I failed to find a similar example of question online, feel free to link if this is a duplicate.

Advertisement

Answer

Using numpy on large data it is much faster than rest

Update — numpy with list comprehension is much faster takes only 0.77s

JavaScript

Comparision of speed

JavaScript
JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement