set_role

DataFrame.set_role(cols, role, time_formats=None)[source]

Assigns a new role to one or more columns.

When switching from a role based on type float to a role based on type string or vice verse, an implicit type conversion will be conducted. The time_formats argument is used to interpret time format string. For more information on roles, please refer to the user guide.

Args:
columns (str, FloatColumn, StringColumn, or List[str, FloatColumn, StringColumn]):

The columns or the names of the columns.

role (str):

The role to be assigned.

time_formats (str or List[str], optional):

Formats to be used to parse the time stamps. This is only necessary, if an implicit conversion from a StringColumn to a time stamp is taking place.

Example:
data_df = dict(
    animal=["hawk", "parrot", "goose"],
    votes=[12341, 5127, 65311],
    date=["04/06/2019", "01/03/2019", "24/12/2018"])
df = getml.DataFrame.from_dict(data_df, "animal_elections")
df.set_role(['animal'], getml.data.roles.categorical)
df.set_role(['votes'], getml.data.roles.numerical)
df.set_role(
    ['date'], getml.data.roles.time_stamp, time_formats=['%d/%m/%Y'])

df
| date                        | animal      | votes     |
| time stamp                  | categorical | numerical |
---------------------------------------------------------
| 2019-06-04T00:00:00.000000Z | hawk        | 12341     |
| 2019-03-01T00:00:00.000000Z | parrot      | 5127      |
| 2018-12-24T00:00:00.000000Z | goose       | 65311     |