Q:

Determine reverse order of data given X/Y coordinates

Imagine an electrical connector. It has pins. Each pin has a corresponding X/Y location in space. I am trying to figure out how to mirror, or 'flip' each pin on the connector given their X/Y coordinate. note:  I am using pandas version 23.4  We can assume that x,y, and pin are not unique but connector is. Connectors can be any size, so two rows of 5, 3 rows of 6, etc.
x    y    pin   connector
1    1     A       1
2    1     B       1
3    1     C       1
1    2     D       1
2    2     E       1
3    2     F       1  
1    1     A       2
2    1     B       2
3    1     C       2
1    2     D       2
2    2     E       2
3    2     F       2

The dataframe column, 'flip', is the solution I am trying to get to. Notice the pins that would be in the same row are now in reverse order.
x    y    pin    flip   connector
1    1     A       C        1
2    1     B       B        1
3    1     C       A        1
1    2     D       F        1
2    2     E       E        1
3    2     F       D        1  
1    1     A       C        2
2    1     B       B        2
3    1     C       A        2
1    2     D       F        2
2    2     E       E        2
3    2     F       D        2

A:

IIUC try using [::-1] a reversing element and groupby with transform:
df['flip'] = df.groupby(['connector','y'])['pin'].transform(lambda x: x[::-1])

Output:
    x  y pin  connector flip
0   1  1   A          1    C
1   2  1   B          1    B
2   3  1   C          1    A
3   1  2   D          1    F
4   2  2   E          1    E
5   3  2   F          1    D
6   1  1   A          2    C
7   2  1   B          2    B
8   3  1   C          2    A
9   1  2   D          2    F
10  2  2   E          2    E
11  3  2   F          2    D

