I have a dataframe that requires a subset of the columns to have entries with multiple values. below is a dataframe with a "runtimes" column that has the runtimes of a program in various conditions:
df = [{"condition": "a", "runtimes": [1,1.5,2]}, {"condition": "b", "runtimes": [0.5,0.75,1]}]
df = pandas.DataFrame(df)
this makes a dataframe:
condition runtimes
0 a [1, 1.5, 2]
1 b [0.5, 0.75, 1]
how can I work with this dataframe and get pandas to treat its values as a numeric list? for example calculate the mean for "runtimes" column across the rows?
df["runtimes"].mean()
gives the error: "Could not convert [1, 1.5, 2, 0.5, 0.75, 1] to numeric"
it'd be useful to work with this dataframes and also to serialize them as csv files where a list like: [1, 1.5, 2]
gets converted into "1,1.5,2"
so that it's still a single entry in the csv file.