I want to rename the indices of my pandas dataframe by retaining only the substring before the third hyphen. My code doesn't modify the indices. Why?
import re
for i in meth_450.index:
re.sub(r"^[^-]*-[^-]*:[^-]*", "", i)
meth_450.index
Index(['TCGA-06-0125-01A-01D-A45W-05', 'TCGA-06-0125-02A-11D-2004-05',
'TCGA-06-0152-01A-02D-A45W-05', 'TCGA-06-0152-02A-01D-2004-05',
'TCGA-06-0171-01A-02D-A45W-05', 'TCGA-06-0171-02A-11D-2004-05',
'TCGA-06-0190-01A-01D-A45W-05', 'TCGA-06-0190-02A-01D-2004-05',
'TCGA-06-0210-01A-01D-A45W-05', 'TCGA-06-0210-02A-01D-2004-05'],
dtype='object', length=155)
Desired output:
TCGA-06-0125, TCGA-06-0125,
TCGA-06-0152, TCGA-06-0152,
TCGA-06-0171, TCGA-06-0171,
TCGA-06-0190, TCGA-06-0190,
TCGA-06-0210, TCGA-06-0210
Ultimately, I want to match this dataframe to another dataframe:
clin = clin[clin.index.isin(meth_450.index)]