Skip to content Skip to sidebar Skip to footer

Avoid Visibledeprecationwarning When Splitting Up Nested Ragged Arrays In A Pandas Dataframe

Question How to not trigger VisibleDeprecationWarning when splitting up a column containing nested ragged arrays into new columns in a Pandas DataFrame? A commonly accepted and str

Solution 1:

Why not give DataFrame a try

df =  df.join(pd.DataFrame(df["col1"].apply(lambda el: (el[0], el[1])).tolist(), 
              index = df.index, 
              columns = ["sep1", "sep2"]))

Solution 2:

How about:

df.join(pd.DataFrame(df['col1'].to_list(), 
                     columns=['sep1','sep2'],index=df.index) 
        )

Output:

  id                 col1          sep1       sep2
0  a  [[1, 2], [3, 4, 5]]        [1, 2]  [3, 4, 5]
1  b     [[6], [7, 8, 9]]           [6]  [7, 8, 9]
2  c   [[10, 11, 12], []]  [10, 11, 12]         []

Post a Comment for "Avoid Visibledeprecationwarning When Splitting Up Nested Ragged Arrays In A Pandas Dataframe"