Conversion Functions
Studio provides several conversion functions, allowing you to cast strings to numbers, or numbers to strings.
| Function | Description |
|---|---|
float(string) | Converts string to a float. Leading characters must be numbers. All input after the last number is ignored. |
int(string) | Converts a string to an integer. Leading characters must be numbers. All input after the decimal point is ignored. |
str(real) | Converts a number to a string. |
float
Convert columns identified as string to the float data type. Numbers past the decimal point are preserved. Any non-number character will end the conversion. For example, $14.32 will not successfully convert into a float. 14.32 dollars will convert to a float.
Example
Suppose progress is a column that contains the following data schema:
| progress |
|---|
| 19.2% complete |
| 51.452% complete |
| 100% complete |
Convert progress to float in a new column progress_float:
float(progress);
The new column will be converted to float:
| progress_float |
|---|
| 19.2 |
| 51.452 |
| 100 |
int
Convert columns identified as string to the int data type. Numbers before the decimal point are preserved. Any non-number character will end the conversion. For example, $14.32 will not convert into an int. 14.32 dollars will convert to an int.
Example
Suppose progress is a column that contains the following data schema:
| progress |
|---|
| 19.2% complete |
| 51.452% complete |
| 100% complete |
Convert progress to int in a new column progress_int:
int(progress);
The new column will be converted to int:
| progress_int |
|---|
| 19 |
| 51 |
| 100 |
str
Converts columns identified as a number (either int or float) to the string data type.
Example
Suppose progress is a column that contains the following data schema:
| progress |
|---|
| 19.2 |
| 51.452 |
| 100 |
Convert progress to string in a new column progress_string:
string(progress) + "% complete";
| progress_string |
|---|
| 19.2% complete |
| 51.452% complete |
| 100% complete |
Updated almost 2 years ago
