2

I'm trying to split a two types of pandas dataframe that contains a column with lists inner.

type 1

col1 col2
------------
foo [foo,hi]
doo [li,ha]

type 2

col1
---------------
[foo, [foo,hi]]
[doo [li,ha]]

Is there a way to split both dataframe in columns and get

col1 col2 col3
--------------
foo, foo, hi
doo, li, ha

Thanks

ambigus9
  • 1,417
  • 3
  • 19
  • 37
  • 1
    `pd.DataFrame([flatten(x) for x in df.to_numpy().tolist()])`. The function in that link is flexible enough to work for both. – ALollz May 10 '19 at 02:54
  • thanks. but it's giving me an error: `NameError: name 'flatten' is not defined` – ambigus9 May 11 '19 at 01:52
  • thanks! it works perfect! @ALollz please propose your answer. – ambigus9 May 11 '19 at 02:43
  • 1
    since the majority of the question can be answered in that other post, I think it should remain a duplicate. Still it is a good question, so I would not delete, as it can direct other people with similar problems to one area with suitable answers. – ALollz May 11 '19 at 02:44

0 Answers0