So I have 2 datasets: 1. an array of data (call it x), 2. a pandas dataframe with n columns
I am trying to write a for loop, which goes through each column in my dataframe
and calculates the correlation coefficient from that column against my first array of data, x.
x = [1.2, 1.9, 2.2, 4.1]
y = {'col1': [1, 2, 3, 4], 'col2': [10, 20, 30, 40]}
example_df = pd.DataFrame(data = y)
for i in example_df.columns:
print(np.corrcoef(x, example_df.i)[0, 1])
However, I am receiving an error
"'DataFrame' object has no attribute 'i'"
I am wondering if anyone has a suggestion for how to access and use 'i'
to access columns in my dataframe
.