Type Conversions
The incoming data may contain a numeric field for an ID Field but it is likely a string field. Or a field has both normal string as well as HTML string and it needs to be treated as HTML. Or a number field actually represents a year. SQL Frames provides the ability to convert the data types of fields. These conversions happen in-place replacing the original values.
It is possible to add type conversions that get invoked while computing the DataFrame by
using the following API available in df.wrangle.convert
object.
Below are the list of type converters.
Converter Name | Comments |
---|---|
tostring(field) | converts any value to a string |
tofloat(field) | converts a string or integer value to a Number type |
tointeger(field) | converts string or numeric values to Number type with 0 decimals |
todate(field,format) | converts a string to a Date type without time component |
todatetime(field,format) | converts a string to a Date type with date and time components |
toyear(field) | converts a date or number value to a Year type |
tomonth(field) | converts a date to a Month type |
toquarter(field) | converts a date to a Quarter type |
tourl(field) | converts a string value to a URL type |
tohtml(field) | converts a string to a HTML type |
toarray(field,separator=',',elementTypeConverter?) | converts a string into an Array |
SQL Frames uses the date-fns library. Refer to date-fns parse
API docs for the format
specification
related to the todate
and todatetime
APIs.
Converting to HTML
Some data such as product feeds can contain HTML in some fields. They are by default recognized as string fields resulting in displaying the markup in the DataFrame tables rather than showing them as HTML. It is possible to convert them to HTML data type and get displayed as HTML.
HTML fields are sanitized using DOMPurify to prevent XSS attacks.