Use app×
Join Bloom Tuition
One on One Online Tuition
JEE MAIN 2025 Foundation Course
NEET 2025 Foundation Course
CLASS 12 FOUNDATION COURSE
CLASS 10 FOUNDATION COURSE
CLASS 9 FOUNDATION COURSE
CLASS 8 FOUNDATION COURSE
0 votes
87 views
in Artificial Intelligence (AI) by (124k points)
How can I find the columns with the highest correlation to a specific column?

Please log in or register to answer this question.

1 Answer

0 votes
by (124k points)

 You can sort the correlation matrix and extract the columns with the highest correlation to a specific column.

import pandas as pd

# Create a sample DataFrame
data = {'A': [1, 2, 3, 4, 5],
        'B': [5, 4, 3, 2, 1],
        'C': [2, 3, 1, 4, 5]}
df = pd.DataFrame(data)

# Calculate the correlation matrix
correlation_matrix = df.corr()

# Find the columns with the highest correlation to column A
most_correlated_columns = correlation_matrix['A'].sort_values(ascending=False).index[1:]
print(f"Columns most correlated with A: {most_correlated_columns}")

Welcome to Sarthaks eConnect: A unique platform where students can interact with teachers/experts/students to get solutions to their queries. Students (upto class 10+2) preparing for All Government Exams, CBSE Board Exam, ICSE Board Exam, State Board Exam, JEE (Mains+Advance) and NEET can ask questions from any subject and get quick answers by subject teachers/ experts/mentors/students.

Categories

...