FunctionRacerProblemsRace

Correlation of Columns

BeginnerpandasPython

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

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More pandas problems