我有一个如下所示的数据框(原始):
Player Name Headline
1 LeBron James LeBron James suggests 5-10 games before playoff
2 LeBron James LeBron James (groin) probable for Thursday
3 LeBron James LeBron James overcomes Pelicans with 34/13/12
4 LeBron James Kyrie Irving (groin) plans to play on Tuesday
5 LeBron James LeBron James (rest) questionable Tuesday
6 LeBron James LeBron James (leg) will start on Saturday
7 LeBron James Kevin Love (hip) is questionable
8 Ryan Anderson Anderson (flu) returns against Cavs on Sunday
9 Ryan Anderson Ryan Anderson out with respiratory infection
10 Ryan Anderson Anderson (rest) not playing
(text)我想删除标题列中没有的所有行。Injury/Rest另外,我想在Location下面标记两个新列。这就是我为实现这一目标所做的工作:
df['Location'] = df.Headline.str.extract('\((.*)\)')[0]
df = df[df['Location'].notnull()]
df['Injury/Rest'] = np.where(df['Location'].eq('rest'), 'Rest', 'Injury')
新输出:
Player Name Headline Location Injury/Rest
-- ------------- --------------------------------------------- ---------- -------------
2 LeBron James LeBron James (groin) probable for Thursday groin Injury
4 LeBron James Kyrie Irving (groin) plans to play on Tuesday groin Injury
5 LeBron James LeBron James (rest) questionable Tuesday rest Rest
6 LeBron James LeBron James (leg) will start on Saturday leg Injury
7 LeBron James Kevin Love (hip) is questionable hip Injury
8 Ryan Anderson Anderson (flu) returns against Cavs on Sunday flu Injury
10 Ryan Anderson Anderson (rest) not playing rest Rest
拉丁的传说
UYOU
相关分类