Correlation of Columns
df has numeric columns x and y, at least two rows, and neither column is constant. Return the correlation between them as a float (a number from -1 to 1; the same value pandas gives for df["x"].corr(df["y"])).
Example 1
df {"x":[1,2,3],"y":[2,4,6]}
returns 1.0
y is exactly 2 * x, so the correlation is 1.0.
Constraints
- Neither column is constant
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.
More pandas problems
- Count Missing ValuesBeginner
- Count Repeated RowsBeginner
- Count Unique CitiesBeginner
- Count in RangeBeginner
- Drop Duplicate PairsBeginner
- Drop a ColumnBeginner
- Everyone ElseBeginner
- Max per ColumnBeginner