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 OverflowPandas
pandas.pydata.org › docs › reference › api › pandas.Series.str.zfill.html
pandas.Series.str.zfill — pandas 3.0.5 documentation - PyData |
>>> s.str.zfill(3) 0 -01 1 001 2 1000 3 NaN 4 NaN dtype: object
w3resource
w3resource.com › pandas › series › series-str-zfill.php
Pandas Series: str.zfill() function - w3resource
May 20, 2026 - The str.zfill() function is used to pad strings in the Series/Index by prepending '0' characters. Strings in the Series/Index are padded with '0' characters on the left of the string to reach a total string length width.
GeeksforGeeks
geeksforgeeks.org › python › 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 › version › 2.0 › reference › api › pandas.Series.str.zfill.html
pandas.Series.str.zfill — pandas 2.0.3 documentation
>>> s.str.zfill(3) 0 -01 1 001 2 1000 3 NaN 4 NaN dtype: object
Top answer 1 of 8
155
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
2 of 8
124
Try:
df['ID'] = df['ID'].apply(lambda x: '{0:0>15}'.format(x))
or even
df['ID'] = df['ID'].apply(lambda x: x.zfill(15))
Pandas
pandas.pydata.org › pandas-docs › stable › reference › api › pandas.Series.str.zfill.html
pandas.Series.str.zfill — pandas 3.0.5 documentation
>>> s.str.zfill(3) 0 -01 1 001 2 1000 3 NaN 4 NaN dtype: object
Pandas
pandas.pydata.org › pandas-docs › version › 0.22 › generated › pandas.Series.str.zfill.html
pandas.Series.str.zfill — pandas 0.22.0 documentation
Filling left side of strings in the Series/Index with 0. Equivalent to str.zfill(). index · modules | next | previous | pandas 0.22.0 documentation » ·
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
str.zfill(width: int) → pyspark.pandas.series.Series¶ · Pad strings in the Series by prepending ‘0’ characters. Strings in the Series are padded with ‘0’ characters on the left of the string to reach a total string length width. Strings in the Series with length greater or equal to width are unchanged.
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
Pandas arrays · Panel · Index objects · Date offsets · Frequencies · Window · GroupBy · Resampling · Style · Plotting · General utility functions · Extensions · Development · Release Notes · Enter search terms or a module, class or function name. Series.str.zfill(self, width)[source]¶ ·
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
>>> s.str.zfill(3) 0 -01 1 001 2 1000 3 NaN 4 NaN dtype: object
Pandas
pandas.pydata.org › pandas-docs › version › 0.16.0 › generated › pandas.Series.str.zfill.html
pandas.Series.str.zfill — pandas 0.16.0 documentation
Contributing to pandas · Internals · Release Notes · Enter search terms or a module, class or function name. Series.str.zfill(width)¶ · ” Filling left side with 0 · index · modules | next | previous | pandas 0.16.0 documentation » · API Reference » ·
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 - The zfill() method is a built-in ... the zero-padding happens after the sign character, not before it. In the context of Pandas, you typically access this function through the .str accessor on a Series....
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).
Pandas
pandas.pydata.org › pandas-docs › version › 1.5 › reference › api › pandas.Series.str.zfill.html
pandas.Series.str.zfill — pandas 1.5.2 documentation
>>> s.str.zfill(3) 0 -01 1 001 2 1000 3 NaN 4 NaN dtype: object
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 - In this tutorial, you’ll learn how to use Python’s zfill method to pad a string with leadering zeroes. You’ll learn how the method works and how to zero pad a string and a number. You’ll also learn how to use the method in Pandas as well as how to use sign prefixes, such as + or -, in your padding.
Pandas
pandas.pydata.org › pandas-docs › version › 2.1.0 › reference › api › pandas.Series.str.zfill.html
pandas.Series.str.zfill — pandas 2.1.0 documentation - PyData |
>>> s.str.zfill(3) 0 -01 1 001 2 1000 3 NaN 4 NaN dtype: object