# Computing on two colums

Code Review Asked by ajayramesh on October 24, 2020

I have this snippet, which computes on two columns, and if I get some increasing pattern then I will consider it a valid Key. How can I optimize this in pandas?

### Sample Code

Here there is only one group of track_id. However, I will have many track_id groups, I need to apply the same for all groups.

import pandas as pd
import numpy as np

tid = [5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 5.,
5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 5.]

j = [ 0.,  0.,  0.,  0.,  0.,  1., 52., 53., -1., -1., -1., -1., -1.,
-1., -1., -1., -1.,  1., -1., -1., -1., -1., -1., -1., -1., -1.,
-1., -1.]

k = [ 0.,  0.,  0.,  0.,  0., -1., -1., -1., -1., -1., 56., 57., 58.,
59., 60., 61., 62., 63., -1., -1., -1., -1., -1., -1., -1., -1.,
-1., -1.]
rules = ['rule_1_start', 'rule_1_end']
data = {'rule_1_start': j, 'rule_1_end': k, 'track_id': tid }
df = pd.DataFrame.from_dict(data)
for r in range(0, len(rules), 2):
track_groups = df.groupby('track_id')
for key, item in track_groups:
_min = np.argmin(item[rules[r]].values)
_max =  np.argmax(item[rules[r+1]].values)
if _min < _max:
print(f"{key}")


### The pattern

I am trying to find is something like this. If you see these two columns, there is increasing value pattern. Col 1 has 77, 78,79 and col 2 has 82-91. The pattern should be increasing from col1 to col2 but not vice versa.

## Related Questions

### C++ linked list inheriting from node class

1  Asked on November 17, 2021 by devinthenrough

### Simple marker rendering

1  Asked on November 17, 2021

### Calculate the first passage time of a sequence consisting of prices

1  Asked on November 15, 2021 by hja24

### C++20 ScopeGuard

1  Asked on November 15, 2021

### LeetCode 146: LRU Cache II

1  Asked on November 13, 2021

### LeetCode 200: Number of Islands

1  Asked on November 13, 2021

### LeetCode 212: Word Search II

1  Asked on November 13, 2021

### LeetCode 284: Peeking Iterator

1  Asked on November 13, 2021

### LeetCode 37: Sudoku Solver

1  Asked on November 13, 2021

### LeetCode 1453: Maximum Number of Darts Inside of a Circular Dartboard

1  Asked on November 13, 2021

### Automating a set a of weekly reports, including graphs and delivery of reports

1  Asked on November 11, 2021 by moo10000

### A VBA Product Dictionary with a Collection of Product Services

2  Asked on November 11, 2021

### Converting a float to a fraction as a string

1  Asked on November 11, 2021 by stonkilla4

### C# consecutive and redundant null checks

6  Asked on November 11, 2021 by frederik-hoeft

### Format string processing similar to date or printf()

2  Asked on November 11, 2021 by domsson

### Improvement to Luhn-Checksum Algorithm in Java

2  Asked on November 11, 2021 by elauser

1  Asked on November 8, 2021

### Python REST API and Mongo – Aggregation Pipeline/Stage classes

1  Asked on November 8, 2021 by rfroes87

### Python palindrome checker function

4  Asked on November 8, 2021 by dicomp