'Python Pandas, comparing rows that have the same values

I have a very difficult question. I am working on an excel file, there are 2 dates and 6 integer columns. What I want to do is to divide this excel file into group of lists where list1= They share only one common number. In the list there must be the common number and the 2 date values of the row. list2= They share only two common numbers. In the list there must be the two common numbers and the 2 date values of the row. the lists goes on till the list6.

I used several ways to get the results. First, I got all the numbers from the columns and added to a list. Then I converted into a dictionary by using Counter to find the number of occurances. Then I converted it to tuples to get the numbers respectively and search among the rows through iterating through columns. However, it I could not manage. I realised that I am not on the right track. Pandas must have a method to help me to compare rows. I am still searching but I lost too much time. I am re-reading the pandas data analysis toolkit on the other hand. Even if you suggest me a source or a method to read I will greatly appreciate it.

 import itertools
   from collections import Counter
   import pandas as pd
   import numpy as np


   df = pd.read_excel('DATASET.xlsx')

   allvaldict = {}
   date_Time= df[['Date','Time']]
   num_cols= df[['one','two','three','four','five','six']]

   tumnofake = []

   for i in range(len(df.columns)-2):
      takelists = df.iloc[:, i+2].tolist()
      tumnofake.append(takelists)

   tumno = list(itertools.chain.from_iterable(tumnofake))

   highlowcommon = [(k, v) for k, v in Counter(tumno).items()]

   def numberreps():
      x=0
      while x<61:
         print([item for item in highlowcommon if item[0] == x])
         x=x+1

I deleted the rest of the codes because they did not work. What I tried to do was to write a function that could satisfy my question.

The result after applying the code for first 50 rows.

df.head(50).to_dict('records')


[{'Date': Timestamp('2020-08-02 00:00:00'), 'Time': datetime.time(20, 0), 'one': 9, 'two': 16, 'three': 18, 'four': 44, 'five': 47, 'six': 51}, {'Date': Timestamp('2020-08-04 00:00:00'), 'Time': datetime.time(20, 0), 'one': 17, 'two': 19, 'three': 32, 'four': 37, 'five': 41, 'six': 54}, {'Date': Timestamp('2020-08-06 00:00:00'), 'Time': datetime.time(20, 0), 'one': 9, 'two': 20, 'three': 21, 'four': 25, 'five': 38, 'six': 53}, {'Date': Timestamp('2020-08-09 00:00:00'), 'Time': datetime.time(20, 0), 'one': 4, 'two': 6, 'three': 14, 'four': 22, 'five': 38, 'six': 58}, {'Date': Timestamp('2020-08-11 00:00:00'), 'Time': datetime.time(20, 0), 'one': 1, 'two': 9, 'three': 14, 'four': 40, 'five': 48, 'six': 58}, {'Date': Timestamp('2020-08-13 00:00:00'), 'Time': datetime.time(21, 30), 'one': 13, 'two': 26, 'three': 29, 'four': 33, 'five': 35, 'six': 50}, {'Date': Timestamp('2020-08-16 00:00:00'), 'Time': datetime.time(21, 30), 'one': 2, 'two': 6, 'three': 17, 'four': 37, 'five': 50, 'six': 53}, {'Date': Timestamp('2020-08-18 00:00:00'), 'Time': datetime.time(21, 30), 'one': 10, 'two': 15, 'three': 17, 'four': 24, 'five': 26, 'six': 32}, {'Date': Timestamp('2020-08-20 00:00:00'), 'Time': datetime.time(21, 30), 'one': 1, 'two': 16, 'three': 21, 'four': 25, 'five': 27, 'six': 33}, {'Date': Timestamp('2020-08-23 00:00:00'), 'Time': datetime.time(21, 30), 'one': 13, 'two': 16, 'three': 35, 'four': 37, 'five': 54, 'six': 56}, {'Date': Timestamp('2020-08-25 00:00:00'), 'Time': datetime.time(21, 30), 'one': 3, 'two': 5, 'three': 6, 'four': 10, 'five': 48, 'six': 60}, {'Date': Timestamp('2020-08-27 00:00:00'), 'Time': datetime.time(21, 30), 'one': 6, 'two': 10, 'three': 31, 'four': 43, 'five': 52, 'six': 59}, {'Date': Timestamp('2020-08-30 00:00:00'), 'Time': datetime.time(21, 30), 'one': 5, 'two': 8, 'three': 19, 'four': 20, 'five': 23, 'six': 43}, {'Date': Timestamp('2020-09-01 00:00:00'), 'Time': datetime.time(21, 30), 'one': 21, 'two': 22, 'three': 28, 'four': 32, 'five': 47, 'six': 50}, {'Date': Timestamp('2020-09-03 00:00:00'), 'Time': datetime.time(21, 30), 'one': 5, 'two': 8, 'three': 10, 'four': 11, 'five': 24, 'six': 31}, {'Date': Timestamp('2020-09-06 00:00:00'), 'Time': datetime.time(21, 30), 'one': 12, 'two': 16, 'three': 28, 'four': 31, 'five': 37, 'six': 43}, {'Date': Timestamp('2020-09-08 00:00:00'), 'Time': datetime.time(21, 30), 'one': 23, 'two': 27, 'three': 30, 'four': 36, 'five': 49, 'six': 54}, {'Date': Timestamp('2020-09-10 00:00:00'), 'Time': datetime.time(21, 30), 'one': 6, 'two': 17, 'three': 26, 'four': 27, 'five': 40, 'six': 48}, {'Date': Timestamp('2020-09-13 00:00:00'), 'Time': datetime.time(21, 30), 'one': 5, 'two': 11, 'three': 26, 'four': 40, 'five': 51, 'six': 53}, {'Date': Timestamp('2020-09-15 00:00:00'), 'Time': datetime.time(21, 30), 'one': 7, 'two': 8, 'three': 24, 'four': 33, 'five': 45, 'six': 46}, {'Date': Timestamp('2020-09-17 00:00:00'), 'Time': datetime.time(21, 30), 'one': 7, 'two': 19, 'three': 37, 'four': 45, 'five': 48, 'six': 53}, {'Date': Timestamp('2020-09-20 00:00:00'), 'Time': datetime.time(21, 30), 'one': 3, 'two': 4, 'three': 7, 'four': 10, 'five': 44, 'six': 47}, {'Date': Timestamp('2020-09-22 00:00:00'), 'Time': datetime.time(21, 30), 'one': 3, 'two': 8, 'three': 33, 'four': 37, 'five': 38, 'six': 44}, {'Date': Timestamp('2020-09-24 00:00:00'), 'Time': datetime.time(21, 30), 'one': 3, 'two': 14, 'three': 20, 'four': 21, 'five': 40, 'six': 55}, {'Date': Timestamp('2020-09-27 00:00:00'), 'Time': datetime.time(21, 30), 'one': 5, 'two': 7, 'three': 8, 'four': 35, 'five': 37, 'six': 44}, {'Date': Timestamp('2020-09-29 00:00:00'), 'Time': datetime.time(21, 30), 'one': 1, 'two': 14, 'three': 20, 'four': 31, 'five': 46, 'six': 50}, {'Date': Timestamp('2020-10-01 00:00:00'), 'Time': datetime.time(21, 30), 'one': 4, 'two': 10, 'three': 33, 'four': 39, 'five': 51, 'six': 54}, {'Date': Timestamp('2020-10-04 00:00:00'), 'Time': datetime.time(21, 30), 'one': 16, 'two': 23, 'three': 29, 'four': 40, 'five': 46, 'six': 51}, {'Date': Timestamp('2020-10-06 00:00:00'), 'Time': datetime.time(21, 30), 'one': 1, 'two': 4, 'three': 20, 'four': 21, 'five': 25, 'six': 29}, {'Date': Timestamp('2020-10-08 00:00:00'), 'Time': datetime.time(21, 30), 'one': 1, 'two': 10, 'three': 21, 'four': 25, 'five': 42, 'six': 48}, {'Date': Timestamp('2020-10-11 00:00:00'), 'Time': datetime.time(21, 30), 'one': 11, 'two': 29, 'three': 38, 'four': 39, 'five': 41, 'six': 57}, {'Date': Timestamp('2020-10-13 00:00:00'), 'Time': datetime.time(21, 30), 'one': 11, 'two': 16, 'three': 22, 'four': 31, 'five': 37, 'six': 52}, {'Date': Timestamp('2020-10-15 00:00:00'), 'Time': datetime.time(21, 30), 'one': 1, 'two': 30, 'three': 31, 'four': 42, 'five': 47, 'six': 59}, {'Date': Timestamp('2020-10-18 00:00:00'), 'Time': datetime.time(21, 30), 'one': 1, 'two': 13, 'three': 18, 'four': 23, 'five': 36, 'six': 53}, {'Date': Timestamp('2020-10-20 00:00:00'), 'Time': datetime.time(21, 30), 'one': 6, 'two': 16, 'three': 30, 'four': 36, 'five': 46, 'six': 58}, {'Date': Timestamp('2020-10-22 00:00:00'), 'Time': datetime.time(21, 30), 'one': 2, 'two': 4, 'three': 15, 'four': 28, 'five': 36, 'six': 52}, {'Date': Timestamp('2020-10-25 00:00:00'), 'Time': datetime.time(21, 30), 'one': 1, 'two': 30, 'three': 38, 'four': 42, 'five': 47, 'six': 52}, {'Date': Timestamp('2020-10-27 00:00:00'), 'Time': datetime.time(21, 30), 'one': 21, 'two': 26, 'three': 31, 'four': 35, 'five': 50, 'six': 58}, {'Date': Timestamp('2020-10-29 00:00:00'), 'Time': datetime.time(21, 30), 'one': 14, 'two': 33, 'three': 40, 'four': 48, 'five': 49, 'six': 60}, {'Date': Timestamp('2020-11-01 00:00:00'), 'Time': datetime.time(21, 30), 'one': 23, 'two': 29, 'three': 37, 'four': 38, 'five': 42, 'six': 43}, {'Date': Timestamp('2020-11-03 00:00:00'), 'Time': datetime.time(21, 30), 'one': 10, 'two': 11, 'three': 12, 'four': 21, 'five': 25, 'six': 49}, {'Date': Timestamp('2020-11-05 00:00:00'), 'Time': datetime.time(21, 30), 'one': 10, 'two': 23, 'three': 39, 'four': 40, 'five': 54, 'six': 56}, {'Date': Timestamp('2020-11-08 00:00:00'), 'Time': datetime.time(21, 30), 'one': 3, 'two': 19, 'three': 39, 'four': 41, 'five': 47, 'six': 53}, {'Date': Timestamp('2020-11-10 00:00:00'), 'Time': datetime.time(21, 30), 'one': 10, 'two': 14, 'three': 20, 'four': 35, 'five': 48, 'six': 60}, {'Date': Timestamp('2020-11-12 00:00:00'), 'Time': datetime.time(21, 30), 'one': 2, 'two': 20, 'three': 41, 'four': 42, 'five': 58, 'six': 60}, {'Date': Timestamp('2020-11-15 00:00:00'), 'Time': datetime.time(21, 30), 'one': 2, 'two': 7, 'three': 14, 'four': 21, 'five': 25, 'six': 42}, {'Date': Timestamp('2020-11-17 00:00:00'), 'Time': datetime.time(21, 30), 'one': 5, 'two': 18, 'three': 24, 'four': 28, 'five': 42, 'six': 51}, {'Date': Timestamp('2020-11-19 00:00:00'), 'Time': datetime.time(21, 30), 'one': 6, 'two': 10, 'three': 29, 'four': 53, 'five': 54, 'six': 55}, {'Date': Timestamp('2020-11-22 00:00:00'), 'Time': datetime.time(21, 30), 'one': 6, 'two': 15, 'three': 22, 'four': 24, 'five': 37, 'six': 44}, {'Date': Timestamp('2020-11-24 00:00:00'), 'Time': datetime.time(21, 30), 'one': 13, 'two': 16, 'three': 36, 'four': 38, 'five': 43, 'six': 48}]


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source