We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
.mean()
1 parent f3f90c3 commit 8f8dfd8Copy full SHA for 8f8dfd8
pandas/core/nanops.py
@@ -43,6 +43,7 @@
43
is_numeric_dtype,
44
is_object_dtype,
45
is_scalar,
46
+ is_string_dtype,
47
is_timedelta64_dtype,
48
needs_i8_conversion,
49
pandas_dtype,
@@ -691,7 +692,11 @@ def nanmean(
691
692
dtype_count = dtype
693
694
count = _get_counts(values.shape, mask, axis, dtype=dtype_count)
- the_sum = _ensure_numeric(values.sum(axis, dtype=dtype_sum))
695
+ the_sum = values.sum(axis, dtype=dtype_sum)
696
+ if isinstance(the_sum, str) or is_string_dtype(the_sum):
697
+ raise TypeError("cannot find the mean of type 'str'")
698
+ else:
699
+ _ensure_numeric(the_sum)
700
701
if axis is not None and getattr(the_sum, "ndim", False):
702
count = cast(np.ndarray, count)
0 commit comments