I have the following data frame:
import pandas as pd
df = pd.DataFrame({ \'gene\':[\"foo\",
\"bar // lal\",
We can first split the column, expand it, stack it and then join it back to the original df like below:
df.drop('gene', axis=1).join(df['gene'].str.split('//', expand=True).stack().reset_index(level=1, drop=True).rename('gene'))
which gives us this:
cell1 cell2 gene
0 5 12 foo
1 9 90 bar
1 9 90 lal
2 1 13 qux
3 7 87 woz