0

I have a df that looks like this:

col1       col2
1          [1,2]

How can I check if df has the list present in the frame so I can apply my flattening logic ?

Example code:

if list present in df == TRUE:
     flatten code
else:
     do nothing
RustyShackleford
  • 3,462
  • 9
  • 40
  • 81
  • 1
    You might be better served with methods that do everything in one fell swoop like here: https://stackoverflow.com/questions/32468402/how-to-explode-a-list-inside-a-dataframe-cell-into-separate-rows. – Polkaguy6000 Jan 09 '19 at 18:05
  • 1
    https://stackoverflow.com/questions/53218931/how-do-i-unnest-explode-a-column-in-a-pandas-dataframe – BENY Jan 09 '19 at 18:07

1 Answers1

1

About the flatten (unnest and explode ) check the link

How to detect them

df.applymap(lambda x : type(x)==list).any()
BENY
  • 317,841
  • 20
  • 164
  • 234