Answer the question
In order to leave comments, you need to log in
How to leave all the repetitions of the second column, in a single variant, while choosing the maximum element from the first column as a pair?
There is such not the most beautiful code:
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
print()
x1 = pd.read_excel("start.xlsx", sheet_name = "x1").to_numpy()
x2 = pd.read_excel("start.xlsx", sheet_name = "x2").to_numpy()
resch = []
resd = []
for i in range(len(x2)):
for j in range(len(x1)):
resch.append(min(x1[j][0],x2[i][0]))
resd.append(round(x1[j][1] + x2[i][1],2))
print(resch)
print("------------------------------")
print(resd)
print("------------------------------")
result = np.array([resch,resd])
result = result.T
print(result)
Answer the question
In order to leave comments, you need to log in
pandas:
result = pd.DataFrame(result)
pd_result = result.groupby(1, as_index=False).max().reindex(columns=[0, 1])
np_result = pd_result.to_numpy()
from collections import defaultdict
data = defaultdict(list)
for value, key in result:
data[key].append(value)
result = [[max(value), key] for key, value in data.items()]
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question