I am trying to unroll a list within a column to add more rows for the purpose of feeding it into a swarmplot.
Right now, I build a dictionary of lists:
# store all list of metrics
clf_aucs = dict()
_list = np.arange(0, 500) # build dummy list of floats
clf_aucs[id] = _list
This dictionary is say 5 keys, each with a list of 500 floats. When I next create a dataframe:
clf_aucs_df = pd.DataFrame(clf_aucs,
).transpose()
clf_aucs_df = clf_aucs_df.reset_index()
display(clf_aucs_df.head())
print(clf_aucs_df.shape)
The result would look like:
index 0 1 2 3 4 5 6 7 8 ... 490 491 492 493 494 495 496 497 498 499
0 clf0 0.432609 0.398760 0.292517 0.411905 0.385375 0.390023 0.364286 0.364035 0.450000 ... 0.477273 0.355372 0.378000 0.386667 0.396104 0.395085 0.426667 0.461957 0.402746 0.445238
1 clf1 0.432900 0.231602 0.416149 0.365217 0.414286 0.461039 0.325217 0.357143 0.447826 ... 0.402893 0.323913 0.420949 0.434783 0.372294 0.360417 0.410208 0.420949 0.392857 0.343685
2 clf2 0.322314 0.400000 0.409524 0.405797 0.466942 0.383399 0.478261 0.405896 0.432892 ... 0.371542 0.494318 0.493750 0.415238 0.414079 0.400433 0.402778 0.493478 0.478261 0.458498
3 clf3 0.509921 0.579051 0.545455 0.658103 0.576560 0.500000 0.515810 0.505682 0.525880 ... 0.590909 0.553360 0.409938 0.462585 0.584348 0.575397 0.472332 0.513834 0.587500 0.612500
4 clf4 0.474206 0.490451 0.479437 0.593750 0.545455 0.580357 0.484127 0.596273 0.537549 ... 0.665909 0.545351 0.609375 0.556277 0.531522 0.511905 0.583851 0.543478 0.513889 0.583333
5 rows × 501 columns
My question is how can I merge the columns 0-499, so that the new dataframe would be 2500 rows x 2 column with the id-column, and the numerical column.
Other attempts:
- tried different ways of creating a dataframe from list of lists
- looked at merge/join, but this in general seemed to be geared towards "combining" separate dataframes and adding columns