【发布时间】:2021-09-30 20:31:58
【问题描述】:
数据帧格式:
| tooth_id | x_center | y_center | width | height | quadrant |
|---|---|---|---|---|---|
| 1 | 0.309643 | 0.082520 | 0.072325 | 0.169476 | |
| 2 | -0.211200 | -0.057675 | 0.071321 | 0.199645 | |
| 3 | -0.307634 | -0.127773 | 0.081366 | 0.187223 | |
| 4 | -0.262933 | -0.093611 | 0.065294 | 0.211180 | |
| 5 | 0.253139 | 0.136646 | 0.096936 | 0.190772 |
问题:如何编写循环来提供以下结果? 在每一卷中:
if x_center >=0 and y_center >= 0, quadrant = 1
if x_center <0 and y_center >= 0, quadrant = 2
if x_center <0 and y_center <0, quadrant = 3
if x_center >0 and y_center <0, quadrant = 4
【问题讨论】:
-
注意:您的象限条件不完全包含笛卡尔平面:
x == 0和y < 0的点未被此逻辑捕获。您应该将 q4 的逻辑更改为x >= 0。
标签: python pandas for-loop where-clause