Python 遍历列表并将结果附加到数据帧
我试图从sportsreference中提取boxscore NFL数据。当您调用单个日期的boxscore数据时,您将在一行中的多个列中获得一组统计数据。因此,我尝试从一个列表中遍历boxscores的多个日期,然后将每一行附加到同一数据帧Python 遍历列表并将结果附加到数据帧,python,pandas,Python,Pandas,我试图从sportsreference中提取boxscore NFL数据。当您调用单个日期的boxscore数据时,您将在一行中的多个列中获得一组统计数据。因此,我尝试从一个列表中遍历boxscores的多个日期,然后将每一行附加到同一数据帧 import pandas as pd from sportsreference.nfl.boxscore import Boxscore boxscore_list = ['201909080mia', '201909150rav', '2019092
import pandas as pd
from sportsreference.nfl.boxscore import Boxscore
boxscore_list = ['201909080mia', '201909150rav', '201909220kan', '201909080phi', '201909150atl']
for x in boxscore_list:
game_data = Boxscore(x)
df = game_data.dataframe
我当前代码中唯一发生的事情是,我获得了单行中的最后一个boxscore。我不知道如何在遍历列表时将所有BoxScore添加到一个数据帧中 您必须附加数据帧,否则df会一直被覆盖
dfs = []
for x in boxscore_list:
game_data = Boxscore(x)
df = game_data.dataframe
dfs.append(df)
result = pd.concat(dfs, ignore_index=True)
非常感谢。真是太棒了!!我想把这些记录附加上去,真是束手无策。