Consider the following columns of a dataset:
ONOFF_LEVER_V0, ONOFF_LEVER_V1, LEDD_DOPA_V0_categ_1, LEDD_DOPA_V1_categ_1
I'd like to transform this dataset in the long format with columns:
visit (0 or 1, corresponding to V0 and V1 respectively), ONOFF_LEVER, LEDD_DOPA_categ_1
I was thinking of using the pd.wide_to_long function, but the suffix V0 or V1 in my case is not always at the end of the variable. Any advice? (this is actually a minimal example of my problem, my dataset is huge).
Use
Series.str.extractwithSeries.str.replaceforMulitIndex, so possible reshape byDataFrame.stack: