From 42f3227d0dbf906123f3111a6103f7cdc75194a3 Mon Sep 17 00:00:00 2001 From: Yuvraj Pradhan <151496266+Yuvraj-Pradhan-27@users.noreply.github.com> Date: Thu, 28 Nov 2024 13:37:58 +0530 Subject: [PATCH] DOC: Added examples for float_format in to_csv documentation --- pandas/core/generic.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index a6be17a654aa7..94c1071055ad3 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -3878,6 +3878,11 @@ def to_csv( >>> import os # doctest: +SKIP >>> os.makedirs("folder/subfolder", exist_ok=True) # doctest: +SKIP >>> df.to_csv("folder/subfolder/out.csv") # doctest: +SKIP + Format floating-point numbers using float_format: + - Format floats to two decimal places: + >>> df.to_csv("out1.csv", float_format="%.2f") # doctest: +SKIP + - Use scientific notation: + >>> df.to_csv("out2.csv", float_format="{:.2e}".format) # doctest: +SKIP """ df = self if isinstance(self, ABCDataFrame) else self.to_frame()