【发布时间】:2020-06-19 03:49:37
【问题描述】:
我有一个Status 列,如下所示:
Status
------------------------
4 probable for Thursday
7 plans to play on Tuesday
8 questionable Tuesday
13 won't play on Sunday
15 will start on Saturday
16 is questionable
17 will not play Thursday
32 questionable Monday
35 good to go vs. CLE
36 probable vs. Cavaliers
37 questionable Monday
40 will not play Saturday
41 drops 35/16/7 on Mavs
42 will play vs. DAL
43 probable vs. Mavericks
45 will play vs. Knicks
47 'hopeful' to play Tues
52 will play on Sunday
55 will play on Saturday
56 headed toward a GTD?
我想创建一个名为Game_Status 的新列。 Game_Status 将过滤 Status 列,如下所示:
Status Game_Status
------------------------ ------------
4 probable for Thursday probable
7 plans to play on Tuesday plans to play
8 questionable Tuesday questionable
13 won't play on Sunday won't play
15 will start on Saturday will start
16 is questionable questionable
17 will not play Thursday will not play
32 questionable Monday questionable
35 good to go vs. CLE good to go
36 probable vs. Cavaliers probable
37 questionable Monday questionable
40 will not play Saturday will not play
41 drops 35/16/7 on Mavs
42 will play vs. DAL will play
43 probable vs. Mavericks probable
45 will play vs. Knicks will play
47 'hopeful' to play Tues hopeful
52 will play on Sunday will play
55 will play on Saturday will play
56 headed toward a GTD? GTD
在第 41 行,Game_Status 将留空,因为找不到任何单词/短语。过滤器将通过这些单词/短语:
gamestatuswords = ['out', 'questionable', 'doubtful','locker room','won\'t return','won\'t play','fractured','sprained','hyperextended','bruised',
'probable to return', 'uncertain', 'game-time decision','miss','weeks', 'GTD','suspended','suspension','day-to-day',
'game time decision', 'broken', 'torn', 'separated', 'ACL','unlikely to play','will not play','without timetable','retire',
'ejected','ejection','probable','hopeful','will play', 'available to play','will start','plans to play','good to go','cleared']
如何实现gamestatuswords 以通过Status 列过滤获得Game_Status 列?
我已经试过了:
df['Game_Status'] = np.where(df['Status'].eq('gamestatuswords'))
【问题讨论】:
标签: python pandas numpy dataframe