I have a data series. I need to find all data segments that look look like U-shape or V-shape. Using the data below as an example, if I define the U-shape or V-shape as starting and ending point with ratio>=0.7 and all points in between are with ratio<0.7 and at least one point in between with ratio<=0.2. With this requirements, I can say two segments in this sample data (12/18/2021 to 12/22/2021, and 12/24/2021 to 12/27/2021) are with U or V shape.

is there some easy way to do this in python or with any package other than writing loops to identify the starting point and nested loop to identify the ending point? Thanks.

| date | ratio |
| --- | --- |
| 12/12/2021 | 0.676 |
| 12/13/2021 | 0.66 |
| 12/14/2021 | 0.682 |
| 12/15/2021 | 0.815 |
| 12/16/2021 | 0.784 |
| 12/17/2021 | 0.649 |
| 12/18/2021 | 0.859 |
| 12/19/2021 | 0.084 |
| 12/20/2021 | 0.156 |
| 12/21/2021 | 0.435 |
| 12/22/2021 | 0.741 |
| 12/23/2021 | 0.671 |
| 12/24/2021 | 0.761 |
| 12/25/2021 | 0.391 |
| 12/26/2021 | 0.126 |
| 12/27/2021 | 0.8 |
| 12/28/2021 | 0.761 |
| 12/29/2021 | 1.025 |
| 12/30/2021 | 0.776 |
| 12/31/2021 | 0.849 |