pd.DataFrame 上的 for 循环继续运行,但在 100 次迭代后停止工作
Posted
技术标签:
【中文标题】pd.DataFrame 上的 for 循环继续运行,但在 100 次迭代后停止工作【英文标题】:For loop over pd.DataFrame continues running but stops working after 100 iterations 【发布时间】:2021-12-13 02:31:49 【问题描述】:我正在尝试对列表中的每个点云应用偏移量,但偏移量在 100 次迭代后停止应用(我手动检查了这个)。没有显示错误。
很遗憾,您将无法运行该代码,因为它使用了一个非常大的本地数据库。
import open3d as o3d
import numpy as np
import pandas as pd
import glob
# offset to calibrate pointclouds for open3d
x_offset = 409000
y_offset = 3660000
# read all paths from dataset and concatenate into east and west matching columns
east_points = pd.DataFrame(glob.glob("/Users/sunny/Desktop/downsampled_pointclouds/east_downsampled/*/*.ply"))
west_points = pd.DataFrame(glob.glob("/Users/sunny/Desktop/downsampled_pointclouds/west_downsampled/*/*.ply"))
points = pd.concat([east_points, west_points], axis = 1, join = "inner")
points.columns = ["east", "west"]
pointclouds_list = []
for index, row in points.iterrows():
east_cloud = o3d.io.read_point_cloud(row["east"])
np.asarray(east_cloud.points)[:,0] -= x_offset
np.asarray(east_cloud.points)[:,1] -= y_offset
west_cloud = o3d.io.read_point_cloud(row["west"])
np.asarray(west_cloud.points)[:,0] -= x_offset
np.asarray(west_cloud.points)[:,1] -= y_offset
parallax_cloud = east_cloud + west_cloud
pointclouds_list.append(parallax_cloud)
east_points
和 points
的长度分别为 23446,west_points
的长度为 24745;我不认为这会导致问题,但我想我还是会提到它。
我打印了索引,循环遍历points
的所有 23446 行。
【问题讨论】:
【参考方案1】:由于您没有提供要使用的数据,我使用 open3d 构建了随机的 .ply
文件,并在随机生成的文件上试用了您的代码。似乎所有偏移量都是从我的数据中应用的。如果要找出问题所在,您可能需要提供有关您的问题的更多信息。
import os
import open3d as o3d
import numpy as np
import pandas as pd
import glob
# offset to calibrate pointclouds for open3d
x_offset = 409000
y_offset = 3660000
if not os.path.exists("east_points"):
os.makedirs("east_points")
if not os.path.exists("west_points"):
os.makedirs("west_points")
# Create random point clouds
for i in range(200):
pcd_east = o3d.geometry.PointCloud()
pcd_west = o3d.geometry.PointCloud()
pcd_east.points = o3d.utility.Vector3dVector(np.random.rand(np.random.randint(10, 1000), 3))
pcd_west.points = o3d.utility.Vector3dVector(np.random.rand(np.random.randint(10, 1000), 3))
o3d.io.write_point_cloud(f"east_points/i_pc.ply", pcd_east)
o3d.io.write_point_cloud(f"west_points/i_pc.ply", pcd_east)
# read all paths from dataset and concatenate into east and west matching columns
east_points = pd.DataFrame(glob.glob("east_points/*.ply"))
west_points = pd.DataFrame(glob.glob("west_points/*.ply"))
points = pd.concat([east_points, west_points], axis = 1, join = "inner")
points.columns = ["east", "west"]
pointclouds_list = []
for index, row in points.iterrows():
east_cloud = o3d.io.read_point_cloud(row["east"])
np.asarray(east_cloud.points)[:,0] -= x_offset
np.asarray(east_cloud.points)[:,1] -= y_offset
west_cloud = o3d.io.read_point_cloud(row["west"])
np.asarray(west_cloud.points)[:,0] -= x_offset
np.asarray(west_cloud.points)[:,1] -= y_offset
parallax_cloud = east_cloud + west_cloud
pointclouds_list.append(parallax_cloud)
print(f"X offset worked for cloud at index index: np.all(np.asarray(parallax_cloud.points)[:,0] < x_offset + 1)")
print(f"Y offset worked for cloud at index index: np.all(np.asarray(parallax_cloud.points)[:,1] < x_offset + 1)")
结果:
X offset worked for cloud at index 0: True
Y offset worked for cloud at index 0: True
X offset worked for cloud at index 1: True
Y offset worked for cloud at index 1: True
X offset worked for cloud at index 2: True
Y offset worked for cloud at index 2: True
X offset worked for cloud at index 3: True
Y offset worked for cloud at index 3: True
X offset worked for cloud at index 4: True
Y offset worked for cloud at index 4: True
X offset worked for cloud at index 5: True
Y offset worked for cloud at index 5: True
X offset worked for cloud at index 6: True
Y offset worked for cloud at index 6: True
X offset worked for cloud at index 7: True
Y offset worked for cloud at index 7: True
X offset worked for cloud at index 8: True
Y offset worked for cloud at index 8: True
X offset worked for cloud at index 9: True
Y offset worked for cloud at index 9: True
X offset worked for cloud at index 10: True
Y offset worked for cloud at index 10: True
X offset worked for cloud at index 11: True
Y offset worked for cloud at index 11: True
X offset worked for cloud at index 12: True
Y offset worked for cloud at index 12: True
X offset worked for cloud at index 13: True
Y offset worked for cloud at index 13: True
X offset worked for cloud at index 14: True
Y offset worked for cloud at index 14: True
X offset worked for cloud at index 15: True
Y offset worked for cloud at index 15: True
X offset worked for cloud at index 16: True
Y offset worked for cloud at index 16: True
X offset worked for cloud at index 17: True
Y offset worked for cloud at index 17: True
X offset worked for cloud at index 18: True
Y offset worked for cloud at index 18: True
X offset worked for cloud at index 19: True
Y offset worked for cloud at index 19: True
X offset worked for cloud at index 20: True
Y offset worked for cloud at index 20: True
X offset worked for cloud at index 21: True
Y offset worked for cloud at index 21: True
X offset worked for cloud at index 22: True
Y offset worked for cloud at index 22: True
X offset worked for cloud at index 23: True
Y offset worked for cloud at index 23: True
X offset worked for cloud at index 24: True
Y offset worked for cloud at index 24: True
X offset worked for cloud at index 25: True
Y offset worked for cloud at index 25: True
X offset worked for cloud at index 26: True
Y offset worked for cloud at index 26: True
X offset worked for cloud at index 27: True
Y offset worked for cloud at index 27: True
X offset worked for cloud at index 28: True
Y offset worked for cloud at index 28: True
X offset worked for cloud at index 29: True
Y offset worked for cloud at index 29: True
X offset worked for cloud at index 30: True
Y offset worked for cloud at index 30: True
X offset worked for cloud at index 31: True
Y offset worked for cloud at index 31: True
X offset worked for cloud at index 32: True
Y offset worked for cloud at index 32: True
X offset worked for cloud at index 33: True
Y offset worked for cloud at index 33: True
X offset worked for cloud at index 34: True
Y offset worked for cloud at index 34: True
X offset worked for cloud at index 35: True
Y offset worked for cloud at index 35: True
X offset worked for cloud at index 36: True
Y offset worked for cloud at index 36: True
X offset worked for cloud at index 37: True
Y offset worked for cloud at index 37: True
X offset worked for cloud at index 38: True
Y offset worked for cloud at index 38: True
X offset worked for cloud at index 39: True
Y offset worked for cloud at index 39: True
X offset worked for cloud at index 40: True
Y offset worked for cloud at index 40: True
X offset worked for cloud at index 41: True
Y offset worked for cloud at index 41: True
X offset worked for cloud at index 42: True
Y offset worked for cloud at index 42: True
X offset worked for cloud at index 43: True
Y offset worked for cloud at index 43: True
X offset worked for cloud at index 44: True
Y offset worked for cloud at index 44: True
X offset worked for cloud at index 45: True
Y offset worked for cloud at index 45: True
X offset worked for cloud at index 46: True
Y offset worked for cloud at index 46: True
X offset worked for cloud at index 47: True
Y offset worked for cloud at index 47: True
X offset worked for cloud at index 48: True
Y offset worked for cloud at index 48: True
X offset worked for cloud at index 49: True
Y offset worked for cloud at index 49: True
X offset worked for cloud at index 50: True
Y offset worked for cloud at index 50: True
X offset worked for cloud at index 51: True
Y offset worked for cloud at index 51: True
X offset worked for cloud at index 52: True
Y offset worked for cloud at index 52: True
X offset worked for cloud at index 53: True
Y offset worked for cloud at index 53: True
X offset worked for cloud at index 54: True
Y offset worked for cloud at index 54: True
X offset worked for cloud at index 55: True
Y offset worked for cloud at index 55: True
X offset worked for cloud at index 56: True
Y offset worked for cloud at index 56: True
X offset worked for cloud at index 57: True
Y offset worked for cloud at index 57: True
X offset worked for cloud at index 58: True
Y offset worked for cloud at index 58: True
X offset worked for cloud at index 59: True
Y offset worked for cloud at index 59: True
X offset worked for cloud at index 60: True
Y offset worked for cloud at index 60: True
X offset worked for cloud at index 61: True
Y offset worked for cloud at index 61: True
X offset worked for cloud at index 62: True
Y offset worked for cloud at index 62: True
X offset worked for cloud at index 63: True
Y offset worked for cloud at index 63: True
X offset worked for cloud at index 64: True
Y offset worked for cloud at index 64: True
X offset worked for cloud at index 65: True
Y offset worked for cloud at index 65: True
X offset worked for cloud at index 66: True
Y offset worked for cloud at index 66: True
X offset worked for cloud at index 67: True
Y offset worked for cloud at index 67: True
X offset worked for cloud at index 68: True
Y offset worked for cloud at index 68: True
X offset worked for cloud at index 69: True
Y offset worked for cloud at index 69: True
X offset worked for cloud at index 70: True
Y offset worked for cloud at index 70: True
X offset worked for cloud at index 71: True
Y offset worked for cloud at index 71: True
X offset worked for cloud at index 72: True
Y offset worked for cloud at index 72: True
X offset worked for cloud at index 73: True
Y offset worked for cloud at index 73: True
X offset worked for cloud at index 74: True
Y offset worked for cloud at index 74: True
X offset worked for cloud at index 75: True
Y offset worked for cloud at index 75: True
X offset worked for cloud at index 76: True
Y offset worked for cloud at index 76: True
X offset worked for cloud at index 77: True
Y offset worked for cloud at index 77: True
X offset worked for cloud at index 78: True
Y offset worked for cloud at index 78: True
X offset worked for cloud at index 79: True
Y offset worked for cloud at index 79: True
X offset worked for cloud at index 80: True
Y offset worked for cloud at index 80: True
X offset worked for cloud at index 81: True
Y offset worked for cloud at index 81: True
X offset worked for cloud at index 82: True
Y offset worked for cloud at index 82: True
X offset worked for cloud at index 83: True
Y offset worked for cloud at index 83: True
X offset worked for cloud at index 84: True
Y offset worked for cloud at index 84: True
X offset worked for cloud at index 85: True
Y offset worked for cloud at index 85: True
X offset worked for cloud at index 86: True
Y offset worked for cloud at index 86: True
X offset worked for cloud at index 87: True
Y offset worked for cloud at index 87: True
X offset worked for cloud at index 88: True
Y offset worked for cloud at index 88: True
X offset worked for cloud at index 89: True
Y offset worked for cloud at index 89: True
X offset worked for cloud at index 90: True
Y offset worked for cloud at index 90: True
X offset worked for cloud at index 91: True
Y offset worked for cloud at index 91: True
X offset worked for cloud at index 92: True
Y offset worked for cloud at index 92: True
X offset worked for cloud at index 93: True
Y offset worked for cloud at index 93: True
X offset worked for cloud at index 94: True
Y offset worked for cloud at index 94: True
X offset worked for cloud at index 95: True
Y offset worked for cloud at index 95: True
X offset worked for cloud at index 96: True
Y offset worked for cloud at index 96: True
X offset worked for cloud at index 97: True
Y offset worked for cloud at index 97: True
X offset worked for cloud at index 98: True
Y offset worked for cloud at index 98: True
X offset worked for cloud at index 99: True
Y offset worked for cloud at index 99: True
X offset worked for cloud at index 100: True
Y offset worked for cloud at index 100: True
X offset worked for cloud at index 101: True
Y offset worked for cloud at index 101: True
X offset worked for cloud at index 102: True
Y offset worked for cloud at index 102: True
X offset worked for cloud at index 103: True
Y offset worked for cloud at index 103: True
X offset worked for cloud at index 104: True
Y offset worked for cloud at index 104: True
X offset worked for cloud at index 105: True
Y offset worked for cloud at index 105: True
X offset worked for cloud at index 106: True
Y offset worked for cloud at index 106: True
X offset worked for cloud at index 107: True
Y offset worked for cloud at index 107: True
X offset worked for cloud at index 108: True
Y offset worked for cloud at index 108: True
X offset worked for cloud at index 109: True
Y offset worked for cloud at index 109: True
X offset worked for cloud at index 110: True
Y offset worked for cloud at index 110: True
X offset worked for cloud at index 111: True
Y offset worked for cloud at index 111: True
X offset worked for cloud at index 112: True
Y offset worked for cloud at index 112: True
X offset worked for cloud at index 113: True
Y offset worked for cloud at index 113: True
X offset worked for cloud at index 114: True
Y offset worked for cloud at index 114: True
X offset worked for cloud at index 115: True
Y offset worked for cloud at index 115: True
X offset worked for cloud at index 116: True
Y offset worked for cloud at index 116: True
X offset worked for cloud at index 117: True
Y offset worked for cloud at index 117: True
X offset worked for cloud at index 118: True
Y offset worked for cloud at index 118: True
X offset worked for cloud at index 119: True
Y offset worked for cloud at index 119: True
X offset worked for cloud at index 120: True
Y offset worked for cloud at index 120: True
X offset worked for cloud at index 121: True
Y offset worked for cloud at index 121: True
X offset worked for cloud at index 122: True
Y offset worked for cloud at index 122: True
X offset worked for cloud at index 123: True
Y offset worked for cloud at index 123: True
X offset worked for cloud at index 124: True
Y offset worked for cloud at index 124: True
X offset worked for cloud at index 125: True
Y offset worked for cloud at index 125: True
X offset worked for cloud at index 126: True
Y offset worked for cloud at index 126: True
X offset worked for cloud at index 127: True
Y offset worked for cloud at index 127: True
X offset worked for cloud at index 128: True
Y offset worked for cloud at index 128: True
X offset worked for cloud at index 129: True
Y offset worked for cloud at index 129: True
X offset worked for cloud at index 130: True
Y offset worked for cloud at index 130: True
X offset worked for cloud at index 131: True
Y offset worked for cloud at index 131: True
X offset worked for cloud at index 132: True
Y offset worked for cloud at index 132: True
X offset worked for cloud at index 133: True
Y offset worked for cloud at index 133: True
X offset worked for cloud at index 134: True
Y offset worked for cloud at index 134: True
X offset worked for cloud at index 135: True
Y offset worked for cloud at index 135: True
X offset worked for cloud at index 136: True
Y offset worked for cloud at index 136: True
X offset worked for cloud at index 137: True
Y offset worked for cloud at index 137: True
X offset worked for cloud at index 138: True
Y offset worked for cloud at index 138: True
X offset worked for cloud at index 139: True
Y offset worked for cloud at index 139: True
X offset worked for cloud at index 140: True
Y offset worked for cloud at index 140: True
X offset worked for cloud at index 141: True
Y offset worked for cloud at index 141: True
X offset worked for cloud at index 142: True
Y offset worked for cloud at index 142: True
X offset worked for cloud at index 143: True
Y offset worked for cloud at index 143: True
X offset worked for cloud at index 144: True
Y offset worked for cloud at index 144: True
X offset worked for cloud at index 145: True
Y offset worked for cloud at index 145: True
X offset worked for cloud at index 146: True
Y offset worked for cloud at index 146: True
X offset worked for cloud at index 147: True
Y offset worked for cloud at index 147: True
X offset worked for cloud at index 148: True
Y offset worked for cloud at index 148: True
X offset worked for cloud at index 149: True
Y offset worked for cloud at index 149: True
X offset worked for cloud at index 150: True
Y offset worked for cloud at index 150: True
X offset worked for cloud at index 151: True
Y offset worked for cloud at index 151: True
X offset worked for cloud at index 152: True
Y offset worked for cloud at index 152: True
X offset worked for cloud at index 153: True
Y offset worked for cloud at index 153: True
X offset worked for cloud at index 154: True
Y offset worked for cloud at index 154: True
X offset worked for cloud at index 155: True
Y offset worked for cloud at index 155: True
X offset worked for cloud at index 156: True
Y offset worked for cloud at index 156: True
X offset worked for cloud at index 157: True
Y offset worked for cloud at index 157: True
X offset worked for cloud at index 158: True
Y offset worked for cloud at index 158: True
X offset worked for cloud at index 159: True
Y offset worked for cloud at index 159: True
X offset worked for cloud at index 160: True
Y offset worked for cloud at index 160: True
X offset worked for cloud at index 161: True
Y offset worked for cloud at index 161: True
X offset worked for cloud at index 162: True
Y offset worked for cloud at index 162: True
X offset worked for cloud at index 163: True
Y offset worked for cloud at index 163: True
X offset worked for cloud at index 164: True
Y offset worked for cloud at index 164: True
X offset worked for cloud at index 165: True
Y offset worked for cloud at index 165: True
X offset worked for cloud at index 166: True
Y offset worked for cloud at index 166: True
X offset worked for cloud at index 167: True
Y offset worked for cloud at index 167: True
X offset worked for cloud at index 168: True
Y offset worked for cloud at index 168: True
X offset worked for cloud at index 169: True
Y offset worked for cloud at index 169: True
X offset worked for cloud at index 170: True
Y offset worked for cloud at index 170: True
X offset worked for cloud at index 171: True
Y offset worked for cloud at index 171: True
X offset worked for cloud at index 172: True
Y offset worked for cloud at index 172: True
X offset worked for cloud at index 173: True
Y offset worked for cloud at index 173: True
X offset worked for cloud at index 174: True
Y offset worked for cloud at index 174: True
X offset worked for cloud at index 175: True
Y offset worked for cloud at index 175: True
X offset worked for cloud at index 176: True
Y offset worked for cloud at index 176: True
X offset worked for cloud at index 177: True
Y offset worked for cloud at index 177: True
X offset worked for cloud at index 178: True
Y offset worked for cloud at index 178: True
X offset worked for cloud at index 179: True
Y offset worked for cloud at index 179: True
X offset worked for cloud at index 180: True
Y offset worked for cloud at index 180: True
X offset worked for cloud at index 181: True
Y offset worked for cloud at index 181: True
X offset worked for cloud at index 182: True
Y offset worked for cloud at index 182: True
X offset worked for cloud at index 183: True
Y offset worked for cloud at index 183: True
X offset worked for cloud at index 184: True
Y offset worked for cloud at index 184: True
X offset worked for cloud at index 185: True
Y offset worked for cloud at index 185: True
X offset worked for cloud at index 186: True
Y offset worked for cloud at index 186: True
X offset worked for cloud at index 187: True
Y offset worked for cloud at index 187: True
X offset worked for cloud at index 188: True
Y offset worked for cloud at index 188: True
X offset worked for cloud at index 189: True
Y offset worked for cloud at index 189: True
X offset worked for cloud at index 190: True
Y offset worked for cloud at index 190: True
X offset worked for cloud at index 191: True
Y offset worked for cloud at index 191: True
X offset worked for cloud at index 192: True
Y offset worked for cloud at index 192: True
X offset worked for cloud at index 193: True
Y offset worked for cloud at index 193: True
X offset worked for cloud at index 194: True
Y offset worked for cloud at index 194: True
X offset worked for cloud at index 195: True
Y offset worked for cloud at index 195: True
X offset worked for cloud at index 196: True
Y offset worked for cloud at index 196: True
X offset worked for cloud at index 197: True
Y offset worked for cloud at index 197: True
X offset worked for cloud at index 198: True
Y offset worked for cloud at index 198: True
X offset worked for cloud at index 199: True
Y offset worked for cloud at index 199: True
【讨论】:
以上是关于pd.DataFrame 上的 for 循环继续运行,但在 100 次迭代后停止工作的主要内容,如果未能解决你的问题,请参考以下文章
如何在 for 循环中向 Pandas Dataframe 添加字符串值?