Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/315.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 我想从更新的API数据创建一个Dataframe,或者使用";至于;环_Python_Dataframe - Fatal编程技术网

Python 我想从更新的API数据创建一个Dataframe,或者使用";至于;环

Python 我想从更新的API数据创建一个Dataframe,或者使用";至于;环,python,dataframe,Python,Dataframe,我需要首先创建一个dict,然后从以下内容创建一个dataframe: # timeline request (single) timeline = trading.in_play_service.get_event_timeline( event_id=event_ids[0] ) print(timeline) for update in timeline.update_detail: print( update.update_type, up

我需要首先创建一个
dict
,然后从以下内容创建一个
dataframe

# timeline request (single)
timeline = trading.in_play_service.get_event_timeline(
    event_id=event_ids[0]
)
print(timeline)
for update in timeline.update_detail:
    print(
        update.update_type,
        update.elapsed_added_time,
        update.team_name,
        update.update_id,
        update.elapsed_regular_time,
        update.update_time,
    )  # view resources or debug to see all values available
现在它只打印来自Betfair API的更新数据,我得到以下结果:

EventTimeline
开球无无9 1 2019-12-20 08:42:44.554000
美国西部黄卡37 22 2019-12-20 09:04:09.506000
黄卡无西悉尼流浪者51 30 2019-12-20 09:12:00.604000
西悉尼流浪者65 38 2019-12-20 09:20:44.413000
前半段2无84 45 2019-12-20 09:29:46.558000
第二阶段开球无87 46 2019-12-20 09:45:46.177000
美国西部黄卡105 61 2019-12-20 10:00:55.977000
无进球西悉尼流浪者队136 79 2019-12-20 10:19:18.448000
进球无西联14787 2019-12-20 10:27:16.620000
第二部分6无163 90 2019-12-20 10:35:56.159000

有什么帮助吗?我是一个新手,在实现交易自动化的过程中,我试图自己解决很多问题。感谢您提供的任何帮助,也欢迎合作。

您可以创建一个空的
数据框,如下所示:

dfObj = pd.DataFrame(columns=['Update_time', 'Team_name', etc...])
然后,您可以在dataFrame对象中填充数据:

for update in timeline.update_detail: 
    dfObj = dfObj.append({'Update_time':update.update_type , 'Team_name': update.team 
    , etc.})
执行此操作后,打印dataFrame对象:

print("Dataframe Contens ", dfObj, sep='\n')

现在,您应该看到包含数据的数据帧。请注意,tmy代码在这种形式下不起作用(它有点伪)。此外,在初始化dataFrame对象时,您应该在dataFrame中定义列的类型。

您能给我看一下print(timeline)的输出吗