str attribute contains most of the methods in string.

df['ID'] = df['ID'].str.zfill(15)

See more: http://pandas.pydata.org/pandas-docs/stable/text.html

Answer from Guangyang Li on Stack Overflow
🌐
Pandas
pandas.pydata.org › docs › reference › api › pandas.Series.str.zfill.html
pandas.Series.str.zfill — pandas 3.0.5 documentation - PyData |
Note that 10 and NaN are not strings, therefore they are converted to NaN. The minus sign in '-1' is treated as a special character and the zero is added to the right of it (str.zfill() would have moved it to the left).
🌐
w3resource
w3resource.com › pandas › series › series-str-zfill.php
Pandas Series: str.zfill() function - w3resource
May 20, 2026 - Pandas Series: str.zfill() function: The str.zfill() function is used to pad strings in the Series/Index by prepending '0' characters.
🌐
GeeksforGeeks
geeksforgeeks.org › python-pandas-series-str-zfill
Python | Pandas Series.str.zfill() | GeeksforGeeks
September 21, 2018 - In this example, a width of 8 is set and zeroes are prefixed to Salary column using zfill() method. Since the Salary column has data type of int64, it's converted to string first using astype() method. ... # importing pandas import pandas as pd # making data frame from csv at url data = pd.read_csv("https://media.geeksforgeeks.org/wp-content/uploads/employees.csv") # converting to string dtype data["Salary"]= data["Salary"].astype(str) # width of output string width = 10 # calling method and overwriting series data["Salary"]= data["Salary"].str.zfill(width) # display data Output: As shown in the output image, zeroes have been prefixed and length of every string in salary column is 10 now.
🌐
Pandas
pandas.pydata.org › pandas-docs › stable › reference › api › pandas.Series.str.zfill.html
pandas.Series.str.zfill — pandas 3.0.5 documentation
Note that 10 and NaN are not strings, therefore they are converted to NaN. The minus sign in '-1' is treated as a special character and the zero is added to the right of it (str.zfill() would have moved it to the left).
🌐
Medium
medium.com › @amit25173 › pandas-zfill-guide-02024316d840
Pandas zfill Guide. The biggest lie in data science? That… | by Amit Yadav | Medium
April 12, 2025 - pandas zfill is primarily used to pad strings with zeros, ensuring a uniform format across your data. ... Simply apply the str.zfill() method to the string column of your DataFrame.
🌐
Statology
statology.org › home › how to use zfill() function in pandas
How to Use zfill() Function in Pandas
April 19, 2024 - It’s important to note that this function only works with string variables. If you attempt to use the function with a numeric column, you will receive a TypeError because the function only works with strings. It’s also important to note that this function only works on pandas Series.
🌐
Databricks
api-docs.databricks.com › python › pyspark › latest › pyspark.pandas › api › pyspark.pandas.Series.str.zfill.html
pyspark.pandas.Series.str.zfill — PySpark master documentation
Note that NaN is not a string, therefore it is converted to NaN. The minus sign in ‘-1’ is treated as a regular character and the zero is added to the left of it (str.zfill() would have moved it to the left).
Find elsewhere
🌐
Pandas
pandas.pydata.org › pandas-docs › version › 0.25.0 › reference › api › pandas.Series.str.zfill.html
pandas.Series.str.zfill — pandas 0.25.0 documentation
Note that 10 and NaN are not strings, therefore they are converted to NaN. The minus sign in '-1' is treated as a regular character and the zero is added to the left of it (str.zfill() would have moved it to the left).
🌐
datagy
datagy.io › home › python posts › python strings › python zfill & rjust: pad a string in python
Python zfill & rjust: Pad a String in Python • datagy
December 16, 2022 - There may be times when you want your Pandas dataframes’ values to be left-padded with zeros. Pandas actually implements the zfill method directly in a Pandas dataframe, meaning that we can apply the function in a vectorized format.
🌐
Pandas
pandas.pydata.org › pandas-docs › version › 2.0 › reference › api › pandas.Series.str.zfill.html
pandas.Series.str.zfill — pandas 2.0.3 documentation
Note that 10 and NaN are not strings, therefore they are converted to NaN. The minus sign in '-1' is treated as a special character and the zero is added to the right of it (str.zfill() would have moved it to the left).
🌐
DECISION STATS
decisionstats.com › 2020 › 12 › 21 › adding-leading-zeros-to-pandas-using-zfill
Adding leading zeros to pandas using zfill – DECISION STATS
December 21, 2020 - pandasdf[“Col1”]= pandasdf[“Col1”].astype(str) width = 5 pandasdf[“Col1”]= pandasdf[“Col1”].str.zfill(width)
🌐
Intelpython
intelpython.github.io › sdc-doc › latest › _api_ref › pandas.Series.str.zfill.html
pandas.Series.str.zfill — Intel® Scalable Dataframe Compiler 0.1 documentation
import pandas as pd from numba import njit @njit def series_str_zfill(): series = pd.Series(['dog', 'foo', 'bar']) # Series of 'dog', 'foo', 'bar' out_series = series.str.zfill(5) return out_series # Expect series of '00dog', '00foo', '00bar' print(series_str_zfill())
🌐
Pandas
pandas.pydata.org › docs › dev › reference › api › pandas.Series.str.zfill.html
pandas.Series.str.zfill — pandas documentation
Note that 10 and NaN are not strings, therefore they are converted to NaN. The minus sign in '-1' is treated as a special character and the zero is added to the right of it (str.zfill() would have moved it to the left).
🌐
Apache
spark.apache.org › docs › latest › api › python › reference › pyspark.pandas › api › pyspark.pandas.Series.str.zfill.html
pyspark.pandas.Series.str.zfill — PySpark 4.2.0 documentation
Note that NaN is not a string, therefore it is converted to NaN. The minus sign in ‘-1’ is treated as a regular character and the zero is added to the left of it (str.zfill() would have moved it to the left).
🌐
Codepointtech
codepointtech.com › home › mastering data formatting: how to use zfill() function in pandas
Mastering Data Formatting: How to Use zfill() Function in Pandas - codepointtech.com
July 4, 2026 - If the string contains a sign character ... access this function through the .str accessor on a Series. This allows you to apply string methods element-wise across an entire column or Series of string data....