构建数据框架

2024-10-01 04:56:16 发布

您现在位置:Python中文网/ 问答频道 /正文

我有下面的数据帧,我想像它一样构造

  id,x,y,time

我的输入数据是这样的 每帧:

point_lists = defaultdict(list)

id= id.astype(np.int32)

point_lists[id].append(center_pt.T)

    saved_x = [i[0] for i in point_lists[id]]
    saved_y = [i[1] for i in point_lists[id]]
    x = list(map(lambda dd: float(dd[0]),saved_x))
    y = list(map(lambda dd: float(dd[0]),saved_y))

现在我想要帕纳达斯

ID1,  List of it's X, List of it's Y, FrameIDX
ID2,  List of it's X, List of it's Y, FrameIDX
ID3,  List of it's X, List of it's Y, FrameIDX

问题是我不能将X和Y的列表连接到数据帧中。 我正在做一个中心(x,y)的视频处理,我不知道如何保持ID-->;List of it's x,List of it's y和当时的帧idx。你知道吗

预期Panadas数据帧示例

  ,trajectory_id,frame,x   ,y   ,t  ,s                  ,v                  ,side,is_primary,s_centered         ,s_normalized       ,is_crossing,is_long,is_close,is_valid
    0 ,1            ,1    ,-2.0,-2.0,0.0,0.0                ,                   ,1   ,True      ,-3.6587033144922905,0.0                ,True       ,True   ,True    ,True
    1 ,1            ,2    ,0.1 ,-1.5,1.0,2.1587033144922905 ,2.1587033144922905 ,1   ,True      ,-1.5               ,0.30304431375902774,True       ,True   ,True    ,True
    2 ,1            ,3    ,0.1 ,0.0 ,2.0,3.6587033144922905 ,1.5                ,1   ,True      ,0.0                ,0.5136181650089165 ,True       ,True   ,True    ,True
    3 ,1            ,4    ,0.1 ,1.5 ,3.0,5.158703314492291  ,1.5                ,-1  ,True      ,1.5000000000000004 ,0.7241920162588055 ,True       ,True   ,True    ,True
    4 ,1            ,5    ,2.0 ,2.0 ,4.0,7.123391584931141  ,1.96468827043885   ,-1  ,True      ,3.46468827043885   ,1.0                ,True       ,True   ,True    ,True
    5 ,2            ,2    ,-2.0,2.0 ,0.0,0.0                ,                   ,-1  ,False     ,-1.9646882704388506,0.0                ,True       ,True   ,True    ,True
    6 ,2            ,3    ,-0.1,1.5 ,1.0,1.9646882704388506 ,1.96468827043885   ,-1  ,False     ,0.0                ,0.27580798374119475,True       ,True   ,True    ,True
    7 ,2            ,4    ,-0.1,0.0 ,2.0,3.4646882704388506 ,1.5                ,1   ,False     ,1.5                ,0.4863818349910837 ,True       ,True   ,True    ,True
    8 ,2            ,5    ,-0.1,-1.5,3.0,4.964688270438849  ,1.5                ,1   ,False     ,2.9999999999999982 ,0.6969556862409724 ,True       ,True   ,True    ,True
    9 ,2            ,6    ,2.0 ,-2.0,4.0,7.123391584931138  ,2.1587033144922905 ,1   ,False     ,5.158703314492287  ,1.0                ,True    

Tags: of数据idfalsetrueforisit