Skip to content

Commit bbe860f

Browse files
committed
Added examples for float_format in to_csv documentation (#60363)
1 parent 7b9a477 commit bbe860f

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

pandas/core/generic.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3878,6 +3878,13 @@ def to_csv(
38783878
>>> import os # doctest: +SKIP
38793879
>>> os.makedirs("folder/subfolder", exist_ok=True) # doctest: +SKIP
38803880
>>> df.to_csv("folder/subfolder/out.csv") # doctest: +SKIP
3881+
3882+
Format floating-point numbers using float_format:
3883+
3884+
- Format floats to two decimal places:
3885+
>>> df.to_csv("out1.csv", float_format="%.2f") # doctest: +SKIP
3886+
- Use scientific notation:
3887+
>>> df.to_csv("out2.csv", float_format="{:.2e}".format) # doctest: +SKIP
38813888
"""
38823889
df = self if isinstance(self, ABCDataFrame) else self.to_frame()
38833890

0 commit comments

Comments
 (0)