VOOZH about

URL: https://www.geeksforgeeks.org/python/formatting-integer-column-of-dataframe-in-pandas/

⇱ Formatting float column of Dataframe in Pandas - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Formatting float column of Dataframe in Pandas

Last Updated : 3 Oct, 2025

Float columns in Pandas often show long decimals or scientific notation. Formatting them by rounding, adding separators, or scaling improves readability while keeping the underlying data unchanged.

This article covers simple ways to format floats in Pandas.

1. Round Off Float Values

You can round float values to a fixed number of decimal places using pd.options.display.float_format.


Output
 Month Expense
0 January 21525220.65
1 February 31125840.88
2 March 23135428.77
3 April 56245263.94

Explanation:

  • pd.options.display.float_format: Sets the display format for floats in Pandas.
  • '{:.2f}'.format: Rounds values to 2 decimal places in fixed-point notation.

2. Format with Separators and Decimal Precision

Adding commas as thousand separators and controlling decimal precision improves clarity.


Output
 Product Price
0 Laptop 1,200.50
1 Phone 799.99
2 Tablet 349.75
3 Desktop 1,500.25

Explanation:

  • '{:,.2f}'.format: Formats numbers with commas and 2 decimal places.
  • .apply(lambda x: ...): Applies the formatting to each element in the column.

3. Scale and Format Numbers

Large numbers can be hard to interpret. Scaling values and applying formatting makes the data easier to read.


Output
 City Population
0 New York 8.34
1 Los Angeles 3.90
2 Chicago 2.71
3 Houston 2.33

Explanation:

  • Dividing by 1000000 scales numbers to millions.
  • '{:,.2f}'.format rounds and adds separators.

Related Articles:

Comment