How to convert a column to a non-nested list while the column elements are list?
For example, the column is like
column
[1, 2, 3]
[1, 2]
I want following at last.
[1,2,3,1,2]
But now with column.tolist()
, I will get
[[1,2,3],[1,2]]
EDIT: Thanks for help. My intention is to find the most simple (elegant) and efficient method to do this. Now I use @jezrael method.
from itertools import chain
output = list(chain.from_iterable(df[column])
The simplest method is provided by @piRSquared, but maybe slower.
output = df[column].values.sum()