Page tree

 

Evaluates a String input against the Decimal datatype. If the input matches, the function outputs a Decimal value. Input can be a literal, a column of values, or a function returning String values.

After you have converted your strings values to decimals, if a sufficient percentage of input strings from a column are successfully converted to the other date type, the column may be retyped. 

Wrangle vs. SQL: This function is part of Wrangle, a proprietary data transformation language. Wrangle is not SQL. For more information, see Wrangle Language.


Basic Usage

parsefloat(strInput)

Output: Returns the Integer data type value for strInput String values.

Syntax and Arguments

parsefloat(str_input)


ArgumentRequired?Data TypeDescription
str_inputYStringLiteral, name of a column, or a function returning String values to match

For more information on syntax standards, see Language Documentation Syntax Notes.

str_input

Literal, column name, or function returning String values that are to be evaluated for conversion to Decimal (Float) values.

  • Missing values for this function in the source data result in null values in the output.
  • Multiple columns and wildcards are not supported.

Usage Notes:


Required?Data TypeExample Value
YesString'5'


Examples

Tip: For additional examples, see Common Tasks.

Example - type parsing functions

This example shows how to use the following parsing functions for evaluating input against the function-specific data type:
  • PARSEBOOL - If the input String value is a valid Boolean value, the value is returned as a Boolean data type value. See PARSEBOOL Function.
  • PARSEDATE - If the input String value is valid against the specified or default Datetime formats, the value is returned as a Datetime value. See PARSEDATE Function.
  • PARSEFLOAT - If the input String value is a valid Float (Decimal) value, the value is returned as a Decimal data type value. See PARSEFLOAT Function.
  • PARSEINT - If the input String value is a valid Integer value, the value is returned as an Integer data type value. See PARSEINT Function.

Source:

The following table contains data on a series of races. 

raceIddisqualifieddateracerIdtime_sc
1FALSE2/1/20124.22
2f2/8/20125
3no2/8/20124.11
4n1-Feb-20226.1
5TRUE8-Feb-202.2-25.22
6t2/8/2020  10:16:00 AM225.44
7yes2/1/20324
8y2/8/203329.22
902/8/20324.78
1011-Feb-20426.2.1
11FALSE8-Feb-20
28.22 sec
12FALSE2/8/2020  10:16:00 AM427.11

As you can see, this dataset has variation in values (FALSE, f, no, n) and problems with the data.

Transformation:

When the data is first imported, it may be properly typed for each column. To use the parsing functions, these columns should be converted to String data type:

Transformation Name Change column data type
Parameter: Columns disqualified,date,racerId,time_sc
Parameter: New type String

Now, you can parse individual columns. 

disqualified column:

Transformation Name Edit column with formula
Parameter: Columns disqualified
Parameter: Formula PARSEBOOL($col)

racerId column:

Transformation Name Edit column with formula
Parameter: Columns racerId
Parameter: Formula PARSEINT($col)

time_sc column:

Transformation Name Edit column with formula
Parameter: Columns time_sc
Parameter: Formula PARSEFLOAT($col)

date column:

For the date column, the PARSEDATE function supports a default set of Datetime formats. Since some of the listed formats are different from these defaults, you must specify all of the formats. These formats are specified as an array of string values as the second argument of the function:

Tip: For the PARSEDATE function, it's useful to use the Preview to verify that all of the dates in the column are represented in the array of output formats. You can see the available output formats through the data type menu at the top of a column. See Choose Datetime Format Dialog.

Transformation Name Edit column with formula
Parameter: Columns date
Parameter: Formula PARSEDATE($col, ['yyyy-MM-dd','yyyy\/MM\/dd','M\/d\/yyy hh:mm','MMMM d, yyyy','MMM d, yyyy'])

After all of the date values have been standardized to the output format of the PARSEDATE function, you may choose to remove the time element of the values:

Transformation Name Replace text or pattern
Parameter: Column date
Parameter: Find ` {digit}{2}:{digit}{2}:{digit}{2}{end}`
Parameter: Replace with ''

Results:

After executing the above steps, the data appears as follows. Notes on each column's output are below the table.

raceIddisqualifieddateracerIdtime_sc
1false2020-02-01124.22
2false2020-02-08125
3false2020-02-08124.11
4false2020-02-01226.1
5true2020-02-08null-25.22
6true2020-02-08225.44
7true2020-02-01324
8true2020-02-083329.22
9false2020-02-08324.78
10true2020-02-014null
11false2020-02-08nullnull
12false2020-02-08427.11

disqualified column:

  • The PARSEBOOL function normalizes all valid Boolean values to either false or true.

racerId column:

  • The PARSEINT function writes invalid values as null values.
  • The function writes empty values as null values.
  • The value 33 remains, since it is a valid Integer. This value should be fixed manually.

time_sc:

  • The PARSEFLOAT function writes the source value 25.00 as 25 in output.
  • The source value -25.22 remains. However, since this is time-based data, it needs to be fixed.
  • Invalid values are written as nulls.

date column:

  • All values are written in the standardized format: yyyy-MM-dd HH:mm:ss. Time data has been stripped.

This page has no comments.