set_role

DataFrame.set_role(names, 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:

names (str or List[str]): The name or names of the column.

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.

Raises:

TypeError: If any of the input arguments has a wrong type.

ValueError: If one of the provided names does not correspond to an existing column.

Example:

data_df = dict(
    animal=["hawk", "parrot", "goose"],
    votes=[12341, 5127, 65311],
    date=["04/06/2019", "01/03/2019", "24/12/2018"])
df = getml.data.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     |