Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/378.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/pandas/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 遍历列表并将结果附加到数据帧_Python_Pandas - Fatal编程技术网

Python 遍历列表并将结果附加到数据帧

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

我试图从sportsreference中提取boxscore NFL数据。当您调用单个日期的boxscore数据时,您将在一行中的多个列中获得一组统计数据。因此,我尝试从一个列表中遍历boxscores的多个日期,然后将每一行附加到同一数据帧

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)

非常感谢。真是太棒了!!我想把这些记录附加上去,真是束手无策。