Zephyr :
I am restructuring the data frame. The sample data frame is as follow:
df = pd.DataFrame()
df ['Stats'] = ['Def duels', 'Def duels Won','Back passes', 'Back passes[Acc]','Dribbles', 'Dribbles[Suc]']
df ['Value'] = [5,2.5,60,55,5,2]
I want to create a new column which only contains the string such as 'Won','Acc' and 'Suc'. The expected data frame is as follow:
Can anyone advise me on this?
Thanks a lot.
YOBEN_S :
IIUC
s=df.Stats.str.contains('Won|Acc|Suc')
df['New']=df.Stats.where(s,'')
df.Stats=df.Stats.mask(s,'')
df
Stats Value New
0 Def duels 5.0
1 2.5 Def duels Won
2 Back passes 60.0
3 55.0 Back passes[Acc]
4 Dribbles 5.0
5 2.0 Dribbles[Suc]
Guess you like
Origin http://43.154.161.224:23101/article/api/json?id=360666&siteId=1