The is my pandas data frame, In the index column i want to keep only the values after double underscore(__) and remove the rest.
2 Answers
Use str.split with parameter n=1 for split by first splitter (if possible multiple __) and select second lists:
df['index'].str.split('__', n=1).str[1]
Or use list comprehension if no missing values and performance is important:
df['last'] = [x.split('__', 1)[1] for x in df['index']]
4 Comments
Shankar Panda
It works fine. Along with the index field, i just want to get all the columns? Any way?
jezrael
@ShankarPanda - So need
df1 = df.join(df['index'].str.split('__', expand=True)) ?Shankar Panda
perfect !! Thanks
