在 for 循环中附加 Dataframe 不起作用
Appending Dataframe in for loop is not working
我快疯了。不知道为什么效果不好
我的循环如下:
for f in tqdm.tqdm(frames[::10]):
col.set_state_from_frame(f)
vertices = generate_dataframe(col)
print(f)
print(vertices)
v_df.append(vertices)
v_df = pd.concat(v_df,keys=frames[::10])
在第一版中我得到:
0
x y coordination charge dx dy
0 -28.384776 -56.769553 3 -1 1.0 -2.0
1 1107.006276 1021.851947 3 -1 -1.0 -2.0
2 1050.236724 1050.236724 2 0 -1.0 1.0
3 965.082395 709.619408 3 -3 0.0 1.0
4 823.158513 1021.851947 3 3 -1.0 0.0
... ... ... ... ... ... ...
1232 1107.006276 709.619408 2 0 -1.0 1.0
1233 652.849855 -85.154329 2 0 1.0 1.0
1234 -28.384776 936.697618 2 -2 1.0 1.0
1235 -28.384776 823.158513 2 2 -1.0 -1.0
1236 -28.384776 766.388960 2 0 -1.0 -1.0
[1237 rows x 6 columns]
10
x y coordination charge dx dy
0 -28.384776 -56.769553 3 -1 1.0 -2.0
1 1107.006276 1021.851947 3 -1 -1.0 -2.0
2 1050.236724 1050.236724 2 0 -1.0 1.0
3 965.082395 709.619408 3 -3 0.0 1.0
4 823.158513 1021.851947 3 3 -1.0 0.0
... ... ... ... ... ... ...
1232 1107.006276 709.619408 2 0 -1.0 1.0
1233 652.849855 -85.154329 2 0 1.0 1.0
1234 -28.384776 936.697618 2 -2 1.0 1.0
1235 -28.384776 823.158513 2 2 -1.0 -1.0
1236 -28.384776 766.388960 2 0 -1.0 -1.0
[1237 rows x 6 columns]
20
x y coordination charge dx dy
0 -28.384776 -56.769553 3 -1 1.0 -2.0
1 1107.006276 1021.851947 3 -1 -1.0 -2.0
2 1050.236724 1050.236724 2 0 -1.0 1.0
3 965.082395 709.619408 3 -3 0.0 1.0
4 823.158513 1021.851947 3 3 -1.0 0.0
... ... ... ... ... ... ...
1232 1107.006276 709.619408 2 0 -1.0 1.0
1233 652.849855 -85.154329 2 0 1.0 1.0
1234 -28.384776 936.697618 2 0 -1.0 1.0
1235 -28.384776 823.158513 2 2 -1.0 -1.0
1236 -28.384776 766.388960 2 0 -1.0 -1.0
[1237 rows x 6 columns]
30
x y coordination charge dx dy
0 -28.384776 -56.769553 3 -1 1.0 -2.0
1 1107.006276 1021.851947 3 -1 -1.0 -2.0
2 1050.236724 1050.236724 2 0 -1.0 1.0
3 965.082395 709.619408 3 -1 2.0 1.0
4 823.158513 1021.851947 3 3 -1.0 0.0
... ... ... ... ... ... ...
1232 1107.006276 709.619408 2 0 -1.0 1.0
1233 652.849855 -85.154329 2 0 1.0 1.0
1234 -28.384776 936.697618 2 0 -1.0 1.0
1235 -28.384776 823.158513 2 0 -1.0 1.0
1236 -28.384776 766.388960 2 0 -1.0 -1.0
但是当我显示以下数据框值时:
v_df.loc[0]
我获得:
x y coordination charge dx dy
0 -28.384776 -56.769553 3 -1 1.0 -2.0
1 1107.006276 1021.851947 3 -1 -1.0 -2.0
2 1050.236724 1050.236724 2 0 -1.0 1.0
3 965.082395 709.619408 3 -1 2.0 1.0
4 823.158513 1021.851947 3 3 -1.0 0.0
... ... ... ... ... ... ...
1232 1107.006276 709.619408 2 0 -1.0 1.0
1233 652.849855 -85.154329 2 0 1.0 1.0
1234 -28.384776 936.697618 2 0 -1.0 1.0
1235 -28.384776 823.158513 2 0 -1.0 1.0
1236 -28.384776 766.388960 2 0 -1.0 -1.0
[1237 rows x 6 columns]
看来这只是连接最后一个值。
PD:查看费用列以查看数据帧之间的差异。
非常感谢!
您正在使用 v_df.loc[0]
,所以它只显示键为 0 的 df。我想如果您打印 v_df
,它会显示所有这些。
我快疯了。不知道为什么效果不好
我的循环如下:
for f in tqdm.tqdm(frames[::10]):
col.set_state_from_frame(f)
vertices = generate_dataframe(col)
print(f)
print(vertices)
v_df.append(vertices)
v_df = pd.concat(v_df,keys=frames[::10])
在第一版中我得到:
0
x y coordination charge dx dy
0 -28.384776 -56.769553 3 -1 1.0 -2.0
1 1107.006276 1021.851947 3 -1 -1.0 -2.0
2 1050.236724 1050.236724 2 0 -1.0 1.0
3 965.082395 709.619408 3 -3 0.0 1.0
4 823.158513 1021.851947 3 3 -1.0 0.0
... ... ... ... ... ... ...
1232 1107.006276 709.619408 2 0 -1.0 1.0
1233 652.849855 -85.154329 2 0 1.0 1.0
1234 -28.384776 936.697618 2 -2 1.0 1.0
1235 -28.384776 823.158513 2 2 -1.0 -1.0
1236 -28.384776 766.388960 2 0 -1.0 -1.0
[1237 rows x 6 columns]
10
x y coordination charge dx dy
0 -28.384776 -56.769553 3 -1 1.0 -2.0
1 1107.006276 1021.851947 3 -1 -1.0 -2.0
2 1050.236724 1050.236724 2 0 -1.0 1.0
3 965.082395 709.619408 3 -3 0.0 1.0
4 823.158513 1021.851947 3 3 -1.0 0.0
... ... ... ... ... ... ...
1232 1107.006276 709.619408 2 0 -1.0 1.0
1233 652.849855 -85.154329 2 0 1.0 1.0
1234 -28.384776 936.697618 2 -2 1.0 1.0
1235 -28.384776 823.158513 2 2 -1.0 -1.0
1236 -28.384776 766.388960 2 0 -1.0 -1.0
[1237 rows x 6 columns]
20
x y coordination charge dx dy
0 -28.384776 -56.769553 3 -1 1.0 -2.0
1 1107.006276 1021.851947 3 -1 -1.0 -2.0
2 1050.236724 1050.236724 2 0 -1.0 1.0
3 965.082395 709.619408 3 -3 0.0 1.0
4 823.158513 1021.851947 3 3 -1.0 0.0
... ... ... ... ... ... ...
1232 1107.006276 709.619408 2 0 -1.0 1.0
1233 652.849855 -85.154329 2 0 1.0 1.0
1234 -28.384776 936.697618 2 0 -1.0 1.0
1235 -28.384776 823.158513 2 2 -1.0 -1.0
1236 -28.384776 766.388960 2 0 -1.0 -1.0
[1237 rows x 6 columns]
30
x y coordination charge dx dy
0 -28.384776 -56.769553 3 -1 1.0 -2.0
1 1107.006276 1021.851947 3 -1 -1.0 -2.0
2 1050.236724 1050.236724 2 0 -1.0 1.0
3 965.082395 709.619408 3 -1 2.0 1.0
4 823.158513 1021.851947 3 3 -1.0 0.0
... ... ... ... ... ... ...
1232 1107.006276 709.619408 2 0 -1.0 1.0
1233 652.849855 -85.154329 2 0 1.0 1.0
1234 -28.384776 936.697618 2 0 -1.0 1.0
1235 -28.384776 823.158513 2 0 -1.0 1.0
1236 -28.384776 766.388960 2 0 -1.0 -1.0
但是当我显示以下数据框值时:
v_df.loc[0]
我获得:
x y coordination charge dx dy
0 -28.384776 -56.769553 3 -1 1.0 -2.0
1 1107.006276 1021.851947 3 -1 -1.0 -2.0
2 1050.236724 1050.236724 2 0 -1.0 1.0
3 965.082395 709.619408 3 -1 2.0 1.0
4 823.158513 1021.851947 3 3 -1.0 0.0
... ... ... ... ... ... ...
1232 1107.006276 709.619408 2 0 -1.0 1.0
1233 652.849855 -85.154329 2 0 1.0 1.0
1234 -28.384776 936.697618 2 0 -1.0 1.0
1235 -28.384776 823.158513 2 0 -1.0 1.0
1236 -28.384776 766.388960 2 0 -1.0 -1.0
[1237 rows x 6 columns]
看来这只是连接最后一个值。
PD:查看费用列以查看数据帧之间的差异。
非常感谢!
您正在使用 v_df.loc[0]
,所以它只显示键为 0 的 df。我想如果您打印 v_df
,它会显示所有这些。