File tree 1 file changed +31
-3
lines changed
1 file changed +31
-3
lines changed Original file line number Diff line number Diff line change @@ -240,10 +240,38 @@ Now the float-dtype is respected. Since the common dtype for these DataFrames is
240
240
241
241
res
242
242
243
- .. _whatsnew_140.notable_bug_fixes.notable_bug_fix3 :
243
+ .. _whatsnew_140.notable_bug_fixes.string_to_numeric_in_mean :
244
244
245
- notable_bug_fix3
246
- ^^^^^^^^^^^^^^^^
245
+ Implicit conversion of string to numeric type in mean
246
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
247
+
248
+ When computing the ``mean `` of a :class: `Series ` or :class: `DataFrame ` with a string-type value, the elements are concatenated
249
+ to a single string then coerced to a numeric type implicitly before computing the mean. This can lead to unexpected results:
250
+
251
+ .. code-block :: ipython
252
+
253
+ In [5]: df = DataFrame({
254
+ "A": ["1", "2", "3"],
255
+ "B": ["0", "1", "J"],
256
+ })
257
+ In [6]: df.mean(numeric_only=False)
258
+ Out[6]:
259
+ A 41.00000+0.00000j
260
+ C 0.000000+0.333333j
261
+ dtype: complex128
262
+
263
+ Now, an exception will be raised whenever ``mean `` is called on string-type columns or :class: `Series `.
264
+
265
+ .. code-block :: ipython
266
+
267
+ In [7]: df = DataFrame({
268
+ "A": ["1", "2", "3"],
269
+ "B": ["0", "1", "J"],
270
+ })
271
+ In [8]: df.mean(numeric_only=False)
272
+ Out[8]:
273
+ ...
274
+ TypeError: cannot find the mean of type 'str'
247
275
248
276
.. ---------------------------------------------------------------------------
249
277
You can’t perform that action at this time.
0 commit comments