Following the Pandas explode() method documentation, one can explode a list in a row into multiple rows:
df = pd.DataFrame({'A': [[1, 2, 3], 'foo', None, [3, 4]], 'B': 1})
df.explode('A')
However, the DataFrame() I get from a database contains lists that are seen as strings :
df = pd.DataFrame({'A': ["[1, 2, 3]", 'foo', None, "[3, 4]"], 'B': 1})
df.explode('A')
# Does not fail, but does not explode "[1, 2, 3]"
Outside Pandas, I use ast.literal_eval() but don't know how to make it work for my column.
How to cast my 'A' column as list so that explode('A') works ?