Teradata Package for Python Function Reference | 20.00 - to_number - Teradata Package for Python - Look here for syntax, methods and examples for the functions included in the Teradata Package for Python.
Teradata® Package for Python Function Reference - 20.00
- Deployment
- VantageCloud
- VantageCore
- Edition
- VMware
- Enterprise
- IntelliFlex
- Product
- Teradata Package for Python
- Release Number
- 20.00.00.11
- Publication Date
- August 2026
- Content Type
- Programming Reference
- Publication ID
- B700-4008-200K
- ft:locale
- en-US
- ft:lastEdition
- 2026-08-13
- ft:sourceId
- FTML
- dita:id
- TeradataPython_FxRef_Enterprise_2000
- Product Category
- Teradata Vantage
- teradataml.dataframe.sql.DataFrameColumn.to_number = to_number(self, formatter=None)
- DESCRIPTION:
Converts a string-like representation of a number to NUMBER type.
PARAMETERS:
formatter:
Optional Argument.
Specifies a variable length string containing formatting characters
that define the format of the columns.
Type: str OR ColumnExpression
Note:
* If 'formatter' is omitted, numeric values is converted to a string exactly
long enough to hold its significant digits.
* Formatters:
+--------------------------------------------------------------------------------------------------+
| FORMATTER DESCRIPTION |
+--------------------------------------------------------------------------------------------------+
| , (comma) A comma in the specified position. |
| A comma cannot begin a number format. |
| A comma cannot appear to the right of a decimal |
| character or period in a number format. |
| Example: |
| +-------------------------------------------------+ |
| | data formatter result | |
| +-------------------------------------------------+ |
| | "1,234" "9,999" 1234 | |
| +-------------------------------------------------+ |
+--------------------------------------------------------------------------------------------------+
| . (period) A decimal point. Only one allowed in a format. |
| Example: |
| +-------------------------------------------------+ |
| | data formatter result | |
| +-------------------------------------------------+ |
| | "12.34" "99.99" 12.34 | |
| +-------------------------------------------------+ |
+--------------------------------------------------------------------------------------------------+
| $ A value with a leading dollar sign. |
| Example: |
| +-------------------------------------------------+ |
| | data formatter result | |
| +-------------------------------------------------+ |
| | "$1234" "$9999" 1234 | |
| +-------------------------------------------------+ |
+--------------------------------------------------------------------------------------------------+
| 0 Leading or trailing zeros. |
| Example: |
| +-------------------------------------------------+ |
| | data formatter result | |
| +-------------------------------------------------+ |
| | "0123" "0999" 123 | |
| | "1230" "9990" 1230 | |
| +-------------------------------------------------+ |
+--------------------------------------------------------------------------------------------------+
| 9 Specified number of digits. |
| Leading space if positive, minus if negative. |
| Example: |
| +-------------------------------------------------+ |
| | data formatter result | |
| +-------------------------------------------------+ |
| | "1234" "9999" 1234 | |
| | "-1234" "9999" -1234 | |
| +-------------------------------------------------+ |
+--------------------------------------------------------------------------------------------------+
| B Blanks if integer part is zero. |
| Example: |
| +-------------------------------------------------+ |
| | data formatter result | |
| +-------------------------------------------------+ |
| | "0" "B9999" 0 | |
| +-------------------------------------------------+ |
+--------------------------------------------------------------------------------------------------+
| C ISO currency symbol (from SDF ISOCurrency). |
| Example: |
| +-------------------------------------------------+ |
| | data formatter result | |
| +-------------------------------------------------+ |
| | "USD123" "C999" 123 | |
| +-------------------------------------------------+ |
+--------------------------------------------------------------------------------------------------+
| D Radix separator for non-monetary values. |
| From SDF RadixSeparator. |
| Example: |
| +-------------------------------------------------+ |
| | data formatter result | |
| +-------------------------------------------------+ |
| | "12.34" "99D99" 12.34 | |
| +-------------------------------------------------+ |
+--------------------------------------------------------------------------------------------------+
| EEEE Scientific notation. |
| Example: |
| +-------------------------------------------------+ |
| | data formatter result | |
| +-------------------------------------------------+ |
| | "1.2E+04" "9.9EEEE" 12000 | |
| +-------------------------------------------------+ |
+--------------------------------------------------------------------------------------------------+
| G Group separator for non-monetary values. |
| From SDF GroupSeparator. |
| Example: |
| +-------------------------------------------------+ |
| | data formatter result | |
| +-------------------------------------------------+ |
| | "1,234,567" "9G999G999" 1234567 | |
| +-------------------------------------------------+ |
+--------------------------------------------------------------------------------------------------+
| L Local currency (from SDF Currency element). |
| Example: |
| +-------------------------------------------------+ |
| | data formatter result | |
| +-------------------------------------------------+ |
| | "$123" "L999" 123 | |
| +-------------------------------------------------+ |
+--------------------------------------------------------------------------------------------------+
| MI Trailing minus sign if value is negative. |
| Can only appear in the last position. |
| Example: |
| +-------------------------------------------------+ |
| | data formatter result | |
| +-------------------------------------------------+ |
| | "1234-" "9999MI" -1234 | |
| +-------------------------------------------------+ |
+--------------------------------------------------------------------------------------------------+
| PR Negative value in angle brackets. |
| Positive value with leading/trailing blank. |
| Only in the last position. |
| Example: |
| +-------------------------------------------------+ |
| | data formatter result | |
| +-------------------------------------------------+ |
| | " 123 " "9999PR" 123 | |
| +-------------------------------------------------+ |
+--------------------------------------------------------------------------------------------------+
| S Sign indicator: + / - at beginning or end. |
| Can only appear in first or last position. |
| Example: |
| +-------------------------------------------------+ |
| | data formatter result | |
| +-------------------------------------------------+ |
| | "-1234" "S9999" -1234 | |
| +-------------------------------------------------+ |
+--------------------------------------------------------------------------------------------------+
| U Dual currency (from SDF DualCurrency). |
| Example: |
| +-------------------------------------------------+ |
| | data formatter result | |
| +-------------------------------------------------+ |
| | "$123" "U999" 123 | |
| +-------------------------------------------------+ |
+--------------------------------------------------------------------------------------------------+
| X Hexadecimal format. |
| Accepts only non-negative values. |
| Must be preceded by 0 or FM. |
| Example: |
| +-------------------------------------------------+ |
| | data formatter result | |
| +-------------------------------------------------+ |
| | "FF" "XX" 255 | |
| +-------------------------------------------------+ |
+--------------------------------------------------------------------------------------------------+
RAISES:
TypeError, ValueError, TeradataMlException
RETURNS:
ColumnExpression
EXAMPLES:
# Load the data to run the example.
>>> load_example_data("teradataml", "to_num_data")
# Create a DataFrame on 'to_num_data' table.
>>> df = DataFrame("to_num_data")
>>> df
price col_format
$1234 $9999
USD123 C999
78.12 99.99
# Example 1: Convert 'price' column to number type without passing any formatter.
>>> res = df.assign(new_col=df.price.to_number())
>>> res
price col_format new_col
$1234 $9999 NaN
USD123 C999 NaN
78.12 99.99 78.12
# Example 2: Convert 'price' column to number type by passing formatter as string.
>>> res = df.assign(new_col=df.price.to_number('99.99'))
>>> res
price col_format new_col
$1234 $9999 NaN
USD123 C999 NaN
78.12 99.99 78.12
# Example 3: Convert 'price' column to number type by passing formatter as ColumnExpression.
>>> res = df.assign(new_col=df.price.to_number(df.col_format))
>>> res
price col_format new_col
$1234 $9999 1234
USD123 C999 123
78.12 99.99 78.12
>>> df.tdtypes
price VARCHAR(length=20, charset='LATIN')
col_format VARCHAR(length=20, charset='LATIN')
new_col NUMBER()