以下是我的数据示例:
In[177]:df_data[['Date', 'TeamName', 'Opponent', 'ScoreOff']].head()
Out[177]:
Date TeamName Opponent ScoreOff
4128 2005-09-08 00:00:00 New England Patriots Oakland Raiders 30
4129 2005-09-08 00:00:00 Oakland Raiders New England Patriots 20
4130 2005-09-11 00:00:00 Arizona Cardinals New York Giants 19
4131 2005-09-11 00:00:00 Baltimore Ravens Indianapolis Colts 7
4132 2005-09-11 00:00:00 Buffalo Bills Houston Texans 22
对于每一行,我需要设置一个新的列['OpponentScoreOff']等于该队对手当天的得分。在
我基本上是这样做的,但是速度很慢,而且我觉得有一种更像Python的/矢量化的方法。在
^{pr2}$它起作用了,但很慢。有更好的办法吗?在
您可以使用
sort
来利用TeamName和Opponent在任何给定日期之间的双向映射。考虑以下因素:数组调用是删除数据帧索引所必需的。这样,一旦数组被放回
df_data
,它就不会被重设。在相关问题 更多 >
编程相关推荐