I have two pandas dataframes. The first dataframe contains the location of different circles over time. Example: df1 = 

```
               x      y      time
circle
 1.0          235    133     1.0
 2.0          236    133     1.0
 3.0          245    425     1.0
 4.0          215    325     2.0
 5.0          287    203     4.0
 6.0          394    394     5.0

```

The second dataframe is organised exactly like the first, but contains the locations of squares at different times. Example: df2 = 

```
               x      y      time
square
 1.0          243    233     1.0
 1.0          293    436     2.0
 2.0          189    230     3.0
 2.0          189    233     4.0
 3.0          176    203     4.0
 3.0          374    394     5.0

```

I would like to figure out how to loop through the dataframe df1 to access all the present squares in df2 at each time point, to find out which is closest.

Example output: 

```
               x      y      time      closest_sq      sq_x      sq_y
circle
 1.0          235    133     1.0          1.0           243       233
 2.0          236    133     1.0          1.0           243       233
 3.0          245    425     1.0          1.0           243       233
 4.0          215    325     2.0          1.0           243       233
 5.0          287    203     4.0          2.0           189       233    
 6.0          394    394     5.0          3.0           374       394 

```

I'm guessing I have to use either iterrows() or itertuples() in a for loop to get at this but I'm not sure, and scipy cdist to get the distance.