You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feature #49580: support new-style float_format string in to_csv (#61650)
* feature #49580: support new-style float_format string in to_csv
feat(to_csv): support new-style float_format strings using str.format
Detect and process new-style format strings (e.g., "{:,.2f}") in the
float_format parameter of to_csv.
- Check if float_format is a string and matches new-style pattern
- Convert it to a callable (e.g., lambda x: float_format.format(x))
- Ensure compatibility with NaN values and mixed data types
- Improves formatting output for floats when exporting to CSV
Example:
df = pd.DataFrame([1234.56789, 9876.54321])
df.to_csv(float_format="{:,.2f}") # now outputs formatted values like
1,234.57
Co-authored-by: Pedro Santos <[email protected]>
* update benchmark test
* fixed pre commit
* fixed offsets.pyx
* fixed tests to windows
* Update pandas/io/formats/format.py
Co-authored-by: Matthew Roeschke <[email protected]>
* Update pandas/io/formats/format.py
Co-authored-by: Matthew Roeschke <[email protected]>
* Update pandas/io/formats/format.py
Co-authored-by: Matthew Roeschke <[email protected]>
* updated v3.0.0.rst and fixed tm.assert_produces_warning
* fixed test_new_style_with_mixed_types_in_column added match to assert_produces_warning
* Update doc/source/whatsnew/v3.0.0.rst (removed reference to this PR)
Co-authored-by: Simon Hawkins <[email protected]>
* fixed pre-commit
* removed tm.assert_produces_warning
* fixed space
* fixed pre-commit
---------
Co-authored-by: Pedro Santos <[email protected]>
Co-authored-by: Matthew Roeschke <[email protected]>
Co-authored-by: Simon Hawkins <[email protected]>
Copy file name to clipboardExpand all lines: doc/source/whatsnew/v3.0.0.rst
+1Lines changed: 1 addition & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -76,6 +76,7 @@ Other enhancements
76
76
- :meth:`.DataFrameGroupBy.transform`, :meth:`.SeriesGroupBy.transform`, :meth:`.DataFrameGroupBy.agg`, :meth:`.SeriesGroupBy.agg`, :meth:`.SeriesGroupBy.apply`, :meth:`.DataFrameGroupBy.apply` now support ``kurt`` (:issue:`40139`)
77
77
- :meth:`DataFrame.apply` supports using third-party execution engines like the Bodo.ai JIT compiler (:issue:`60668`)
78
78
- :meth:`DataFrame.iloc` and :meth:`Series.iloc` now support boolean masks in ``__getitem__`` for more consistent indexing behavior (:issue:`60994`)
79
+
- :meth:`DataFrame.to_csv` and :meth:`Series.to_csv` now support Python's new-style format strings (e.g., ``"{:.6f}"``) for the ``float_format`` parameter, in addition to old-style ``%`` format strings and callables. This allows for more flexible and modern formatting of floating point numbers when exporting to CSV. (:issue:`49580`)
79
80
- :meth:`DataFrameGroupBy.transform`, :meth:`SeriesGroupBy.transform`, :meth:`DataFrameGroupBy.agg`, :meth:`SeriesGroupBy.agg`, :meth:`RollingGroupby.apply`, :meth:`ExpandingGroupby.apply`, :meth:`Rolling.apply`, :meth:`Expanding.apply`, :meth:`DataFrame.apply` with ``engine="numba"`` now supports positional arguments passed as kwargs (:issue:`58995`)
80
81
- :meth:`Rolling.agg`, :meth:`Expanding.agg` and :meth:`ExponentialMovingWindow.agg` now accept :class:`NamedAgg` aggregations through ``**kwargs`` (:issue:`28333`)
81
82
- :meth:`Series.map` can now accept kwargs to pass on to func (:issue:`59814`)
0 commit comments