File tree 1 file changed +33
-0
lines changed
1 file changed +33
-0
lines changed Original file line number Diff line number Diff line change @@ -346,6 +346,39 @@ second column is instead renamed to ``a.2``.
346
346
347
347
res
348
348
349
+ .. _whatsnew_140.notable_bug_fixes.mean_implicit_conversion_to_numeric :
350
+
351
+ Implicit conversion of string to numeric type in mean
352
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
353
+
354
+ When computing the ``mean `` of a :class: `Series ` or :class: `DataFrame ` with a string-type value, the elements are concatenated
355
+ to a single string then coerced to a numeric type implicitly before computing the mean. This can lead to unexpected results:
356
+
357
+ .. code-block :: ipython
358
+
359
+ In [5]: df = DataFrame({
360
+ "A": ["1", "2", "3"],
361
+ "B": ["0", "1", "J"],
362
+ })
363
+ In [6]: df.mean(numeric_only=False)
364
+ Out[6]:
365
+ A 41.00000+0.00000j
366
+ C 0.000000+0.333333j
367
+ dtype: complex128
368
+
369
+ Now, an exception will be raised whenever ``mean `` is called on a string-type column or :class: `Series `.
370
+
371
+ .. code-block :: ipython
372
+
373
+ In [7]: df = DataFrame({
374
+ "A": ["1", "2", "3"],
375
+ "B": ["0", "1", "J"],
376
+ })
377
+ In [8]: df.mean(numeric_only=False)
378
+ Out[8]:
379
+ ...
380
+ TypeError: cannot find the mean of type 'str'
381
+
349
382
.. _whatsnew_140.notable_bug_fixes.notable_bug_fix3 :
350
383
351
384
notable_bug_fix3
You can’t perform that action at this time.
0 commit comments