DEPR: groupby.corrwith · Issue #57158 · pandas-dev/pandas (original) (raw)
As far as I can tell, corrwith was added simply because it could be along with other methods on DataFrame. Searching SO gives two results, of which corrwith
is not involved in the solution for both. I'm guessing this method really doesn't see much if any use.
It's signature is odd - it pairs each of the groups up with a single DataFrame and aligns them.
df = pd.DataFrame({"a": [1, 1, 1, 2, 2, 2], "b": range(6)})
df2 = pd.DataFrame({"a": [1, 1, 1, 2, 2, 2, 3], "b": [10 - e for e in range(3)] + list(range(3)) + [10]})
gb = df.groupby("a")
print(gb.corrwith(df2))
# b a
# a
# 1 -1.0 NaN
# 2 1.0 NaN
I'm thinking we should deprecate this method.