Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -5588,10 +5588,11 @@ def corrwith(self, other, axis=0, drop=False):
correls : Series
"""
axis = self._get_axis_number(axis)
this = self._get_numeric_data()

if isinstance(other, Series):
return self.apply(other.corr, axis=axis)
return this.apply(other.corr, axis=axis)

this = self._get_numeric_data()
other = other._get_numeric_data()

left, right = this.align(other, join='inner', copy=False)
Expand Down
9 changes: 9 additions & 0 deletions pandas/tests/frame/test_analytics.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,15 @@ def test_corrwith_matches_corrcoef(self):
tm.assert_almost_equal(c1, c2)
assert c1 < 1

def test_corrwith_mixed_dtypes(self):
df = pd.DataFrame({'a': [1, 4, 3, 2], 'b': [4, 6, 7, 3],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add the issue number as a comment

'c': ['a', 'b', 'c', 'd']})
s = pd.Series([0, 6, 7, 3])
result = df.corrwith(s)
corrs = [df['a'].corr(s), df['b'].corr(s)]
expected = pd.Series(data=corrs, index=['a', 'b'])
tm.assert_series_equal(result, expected)

def test_bool_describe_in_mixed_frame(self):
df = DataFrame({
'string_data': ['a', 'b', 'c', 'd', 'e'],
Expand Down