str.format() is making your fields left aligned within the available space. Use alignment specifiers to change the alignment:

'<' Forces the field to be left-aligned within the available space (this is the default for most objects).

'>' Forces the field to be right-aligned within the available space (this is the default for numbers).

'=' Forces the padding to be placed after the sign (if any) but before the digits. This is used for printing fields in the form โ€˜+000000120โ€™. This alignment option is only valid for numeric types.

'^' Forces the field to be centered within the available space.

Here's an example (with both left and right alignments):

>>> for args in (('apple', '$1.09', '80'), ('truffle', '$58.01', '2')):
...     print '{0:<10} {1:>8} {2:>8}'.format(*args)
...
apple         $1.09       80
truffle      $58.01        2
Answer from Steven Rumbalski on Stack Overflow
๐ŸŒ
Delft Stack
delftstack.com โ€บ home โ€บ howto โ€บ python โ€บ python print column alignment
How to Print With Column Alignment in Python | Delft Stack
February 22, 2025 - For basic text formatting, format() or f-strings are the best options. For structured tabular data, tabulate and pandas provide automated formatting that ensures consistent alignment.
๐ŸŒ
Python documentation
docs.python.org โ€บ 3 โ€บ tutorial โ€บ inputoutput.html
7. Input and Output โ€” Python 3.14.7 documentation
The example also prints percentage multiplied by 100, with 2 decimal places and followed by a percent sign (see Format specification mini-language for details). Finally, you can do all the string handling yourself by using string slicing and concatenation operations to create any layout you can imagine. The string type has some methods that perform useful operations for padding strings to a given column width.
๐ŸŒ
Bentley
cissandbox.bentley.edu โ€บ sandbox โ€บ wp-content โ€บ uploads โ€บ 2022-02-10-Documentation-on-f-strings-Updated.pdf pdf
A Guide to Formatting with f-strings in Python - CIS Sandbox
Program output is often required to be in tabular form. f-strings are very useful in formatting ยท this kind of output. The following lines produce a tidily aligned set of columns with integers and
๐ŸŒ
ProjectPro
projectpro.io โ€บ recipes โ€บ format-string-in-pandas-dataframe-column
How to format string in a Pandas DataFrame Column? -
January 19, 2023 - So for this there are predefined functions are available in python. This python source code does the following : 1. Creates a pandas series 2. Converts strings into lower and upper format 3. performs splits and capitalization ยท So this is the recipe on how we can format string in a Pandas DataFrame Column.
๐ŸŒ
GitHub
gist.github.com โ€บ alexland โ€บ 9521179
printing formatted tables using python 3 "advanced string formatting" ยท GitHub
March 26, 2019 - printing formatted tables using python 3 "advanced string formatting" - column-print.py
Find elsewhere
๐ŸŒ
Talkerscode
talkerscode.com โ€บ howto โ€บ python-formatting-output-into-columns.php
Python Formatting Output Into Columns
July 1, 2023 - Users frequently require moreover ... format output. To utilize formatted string literals, commence a string with f or F before the opening quote mark or triplex quote mark....
๐ŸŒ
Scientifically Sound
scientificallysound.org โ€บ 2016 โ€บ 10 โ€บ 17 โ€บ python-print3
Take control of your Python print() statements: part 3 | Scientifically Sound
November 17, 2021 - In the last post, we learned how to control the precision of the number we print as well as the number of spaces these numbers take up. The last thing we need to learn to output nice data tables is how to align text and numbers when we use .format(). Aligning text and numbers withโ€ฆ
๐ŸŒ
ZetCode
zetcode.com โ€บ python โ€บ fstring
Python f-string - formatting strings in Python with f-string
May 11, 2025 - $ python main.py Always show sign: +42 -42 +0 Default behavior: 42 -42 0 Space for positive: 42 -42 0 Aligned column: +42 -42 +0 ยท F-strings can also format complex numbers, allowing you to control the display of their real and imaginary parts.
๐ŸŒ
Towards Data Science
towardsdatascience.com โ€บ home โ€บ latest โ€บ apply thousand separator (and other formatting) to pandas dataframe
Apply Thousand Separator (and Other Formatting) to Pandas Dataframe | Towards Data Science
January 28, 2025 - Let's start with the 'Median Sales Price' column and see how we can format it by adding the thousand comma separators and a dollar sign in the front. Below is the code that does the trick: ... We use the python string format syntax '{:,.0f}'.format to add the thousand comma separators to the ...
๐ŸŒ
OpenStax
openstax.org โ€บ books โ€บ introduction-python-programming โ€บ pages โ€บ 8-4-string-formatting
8.4 String formatting - Introduction to Python Programming | OpenStax
March 13, 2024 - Format a string template using input arguments. Use format() to generate numerical formats based on a given template. Python provides string substitutions syntax for formatting strings with input arguments.
๐ŸŒ
Blogger
knowledgestockpile.blogspot.com โ€บ 2011 โ€บ 01 โ€บ string-formatting-in-python_09.html
knowledge stockpile: String formatting in Python
September 1, 2011 - if you specify two or more flags they should be specified in the same order as shown in the general form of the format specifier. if you want to use the fill, you must give a value for the align flag. Let us first set the column width. The minimumwidth flag allows us to do this.
๐ŸŒ
SQLPad
sqlpad.io โ€บ tutorial โ€บ python-formatted-output
Python formatted output | SQLPad
April 29, 2024 - We then use these widths to create a format string for each column, ensuring that each piece of data aligns neatly in the table. Nested field replacement is a versatile tool that can save you time and make your code more readable, especially when dealing with variable formatting or when outputting data in a structured format like tables. It's an advanced feature that, once mastered, can greatly enhance the presentation of data in your Python ...
๐ŸŒ
YouTube
youtube.com โ€บ brad yourth
f-strings and column control - YouTube
Demonstrates f-strings for formatting columns with specified widths, alignment, and decimals.
Published: December 20, 2020
Views: 2K
๐ŸŒ
Pandas
pandas.pydata.org โ€บ docs โ€บ reference โ€บ api โ€บ pandas.io.formats.style.Styler.format.html
pandas.io.formats.style.Styler.format โ€” pandas 3.0.5 documentation
If a callable then that function should take a data value as input and return a displayable representation, such as a string. If formatter is given as a string this is assumed to be a valid Python format specification and is wrapped to a callable as string.format(x). If a dict is given, keys should correspond to column names, and values should be string or callable, as above.