I would like to extend the question: splitting a column by delimiter pandas python
import pandas as pd
df = {'V': ['IGHV7-B*01','IGHV7-B*01','IGHV6-A*01','GHV6-A*01','IGHV6-A*01','IGHV6-A*01','IGHV4- L*03','IGHV4-L*03','IGHV5-A*01','IGHV5-A*04','IGHV6-A*02','IGHV6-A*02']}
Now, I would like to only keep the new names:
df[['Name','allele']] = df['V'].str.split('-',expand=True)
But the df stores "V" too:
df
V Name allele
0 IGHV7-B*01 IGHV7 B*01
1 IGHV7-B*01 IGHV7 B*01
... Is there a handy key for doing that? I know I can do:
df.drop(columns='V', axis=1, inplace=True)
I would prefer a key instead of another line of code, as in my project, I have to repeat the same thing several times and I have a total of 25 names there.