Question: I have a data frame according to below:

```

id_1  id_2  value
1     0     1
1     1     2
1     2     3
2     0     4
2     1     1
3     0     5
3     1     1
4     0     5
4     1     1
4     2     6
4     3     7  
11    0     8
11    1     14
13    0     10
13    1     9 

```

I would like to take out a random sample of size n, without replacement, from this table based on *id\_1*. This row needs to be unique with respect to the *id\_1* column and can only occur once. 

End result something like:

```

id_1  id_2  value
1     1     2
2     0     4
4     3     7
13    0     10

```

I have tried to do a group by and use the indices to take out a row through *random.sample* but it dosent go all the way. 

Can someone give me a pointer on how to make this work? Code for DF below!

As always, thanks for time and input!

/swepab

```
df = pd.DataFrame({'id_1' : [1,1,1,2,2,3,3,4,4,4,4,11,11,13,13],
               'id_2' : [0,1,2,0,1,0,1,0,1,2,3,0,1,0,1],
               'value_col' : [1,2,3,4,1,5,1,5,1,6,7,8,14,10,9]})

```

Answer: 
Step 1: Add swipe Gesture(s) in **viewDidLoad()** method.

```
override func viewDidLoad() {
    super.viewDidLoad()

    let swipeLeft = UISwipeGestureRecognizer(target: self, action: #selector(handleGesture))
    swipeLeft.direction = .left
    self.view.addGestureRecognizer(swipeLeft)

    let swipeRight = UISwipeGestureRecognizer(target: self, action: #selector(handleGesture))
    swipeRight.direction = .right
    self.view.addGestureRecognizer(swipeRight)

    let swipeUp = UISwipeGestureRecognizer(target: self, action: #selector(handleGesture))
    swipeUp.direction = .up
    self.view.addGestureRecognizer(swipeUp)

    let swipeDown = UISwipeGestureRecognizer(target: self, action: #selector(handleGesture))
    swipeDown.direction = .down
    self.view.addGestureRecognizer(swipeDown)
}

```

Step 2: Check the gesture detection in **handleGesture()** method

```
func handleGesture(gesture: UISwipeGestureRecognizer) {
   if gesture.direction == .right {
        print("Swipe Right")
   }
   else if gesture.direction == .left {
        print("Swipe Left")
   }
   else if gesture.direction == .up {
        print("Swipe Up")
   }
   else if gesture.direction == .down {
        print("Swipe Down")
   }
}

```

I hope this will help someone.

UPDATE:

You need to use @objc to call your 'Selector' method for latest swift versions.
ie,

```
@objc func handleGesture(gesture: UISwipeGestureRecognizer) -> Void {
  .
  .
  .
}

```
```
    func holeSwiped(gesture: UISwipeGestureRecognizer)
    {
    if let swipeGesture = gesture as? UISwipeGestureRecognizer{
    switch swipeGesture.direction {
    case UISwipeGestureRecognizerDirection.right:
        NSLog("right swipe")
    case UISwipeGestureRecognizerDirection.left:
        NSLog("left swipe")
    default:
        NSLog("other swipe")
    }
   }
  }

```