Таким образом, я выбрал подмножество численных столбцов из базы данных - я хочу итерацию через столбцы, выбрав целевой столбец и сравнивая его с результатом численной работы между двумя другими столбцами в DataFrame, однако я не уверен в том, как сравнить «результат», например, COL1 умножен на Col 2 = Целевой столбец. < /p>
# For all possible combinations of numeric columns
for col1, col2 in combinations(numeric_cols, 2):
# For a target column in numeric_columns
for target_column in numeric_cols:
# Skip if the target column is one of the relationship columns
if target_column in (col1, col2):
continue
< /code>
Редактировать ** Я что -то произвел, но все еще не уверен, является ли это наиболее эффективным способом сделать это - игнорировать порог < /p>
def analyse_relationships(df):
numeric_cols = df.select_dtypes(include=[np.number])
threshold = 0.001
relationships = []
# For all possible combinations of numeric columns
for col1, col2 in combinations(numeric_cols, 2):
# For a target column in numeric_columns
for target_column in numeric_cols:
# Skip if the target column is one of the relationship columns
if target_column in (col1, col2):
continue
# Calculate different operations
product = numeric_cols[col1] * numeric_cols[col2]
sum_cols = numeric_cols[col1] + numeric_cols[col2]
diff = numeric_cols[col1] - numeric_cols[col2]
if np.allclose(product, numeric_cols[target_column], rtol=threshold):
relationships.append(f"{col1} * {col2} = {target_column}")
elif np.allclose(sum_cols, numeric_cols[target_column], rtol=threshold):
relationships.append(f"{col1} + {col2} = {target_column}")
elif np.allclose(diff, numeric_cols[target_column], rtol=threshold):
relationships.append(f"{col1} - {col2} = {target_column}")
Подробнее здесь: https://stackoverflow.com/questions/795 ... en-columns
Поиск численных отношений между столбцами ⇐ Python
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение
-
-
Альтернативы ArrayList
для примитивных типов в Java для численных вычислений
Anonymous » » в форуме JAVA - 0 Ответы
- 20 Просмотры
-
Последнее сообщение Anonymous
-
-
-
Альтернативы ArrayList
для примитивных типов в Java для численных вычислений
Anonymous » » в форуме JAVA - 0 Ответы
- 12 Просмотры
-
Последнее сообщение Anonymous
-