Teradata Package for Python Function Reference | 20.00 - unhex - 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
- Enterprise
- IntelliFlex
- VMware
- Product
- Teradata Package for Python
- Release Number
- 20.00.00.03
- Published
- December 2024
- ft:locale
- en-US
- ft:lastEdition
- 2024-12-19
- dita:id
- TeradataPython_FxRef_Enterprise_2000
- lifecycle
- latest
- Product Category
- Teradata Vantage
- teradataml.dataframe.sql.DataFrameColumn.unhex = unhex(self)
- DESCRIPTION:
Function to compute the decimal from Hexadecimal for the column.
RETURNS:
ColumnExpression.
EXAMPLES:
# Load the data to run the example.
>>> load_example_data("teradataml","titanic")
# Create a DataFrame on 'titanic' table.
>>> titanic = DataFrame.from_table('titanic')
>>> df = titanic.select(["passenger", "age", "fare"])
>>> print(df)
age fare
passenger
326 36.0 135.6333
183 9.0 31.3875
652 18.0 23.0000
265 NaN 7.7500
530 23.0 11.5000
122 NaN 8.0500
591 35.0 7.1250
387 1.0 46.9000
734 23.0 13.0000
795 25.0 7.8958
>>>
# create a "age_in_hex" column which contains hexadecimal values
>>> hex_df = df.assign(age_in_hex=df.age.hex())
>>> print(hex_df)
age fare age_in_hex
passenger
530 23.0 11.500 17
591 35.0 7.125 23
387 1.0 46.900 1
856 18.0 9.350 12
244 22.0 7.125 16
713 48.0 52.000 30
448 34.0 26.550 22
122 NaN 8.050 None
734 23.0 13.000 17
265 NaN 7.750 None
>>>
# Example 1: Converts values in "age_in_hex" hexadecimal to decimal and pass it as input to
# DataFrame.assign().
>>> unhex_df = hex_df.assign(age_in_decimal=hex_df.age_in_hex.unhex())
>>> print(unhex_df)
age fare age_in_hex age_in_decimal
passenger
326 36.0 135.6333 24 36
183 9.0 31.3875 9 9
652 18.0 23.0000 12 18
40 14.0 11.2417 E 14
774 NaN 7.2250 None None
366 30.0 7.2500 1E 30
509 28.0 22.5250 1C 28
795 25.0 7.8958 19 25
61 22.0 7.2292 16 22
469 NaN 7.7250 None None
>>>