getml.data.Roles
Roles dataclass
Roles(
categorical: Iterable[str] = tuple(),
join_key: Iterable[str] = tuple(),
numerical: Iterable[str] = tuple(),
target: Iterable[str] = tuple(),
text: Iterable[str] = tuple(),
time_stamp: Iterable[str] = tuple(),
unused_float: Iterable[str] = tuple(),
unused_string: Iterable[str] = tuple(),
)
Roles can be passed to DataFrame
to predefine the roles assigned to certain columns.
ATTRIBUTE | DESCRIPTION |
---|---|
categorical | Names of the categorical columns. |
join_key | Names of the join key columns. |
numerical | Names of the numerical columns. |
target | Names of the target columns. |
text | Names of the text columns. |
time_stamp | Names of the time stamp columns. |
unused_float | Names of the unused float columns. |
unused_string | Names of the unused string columns. |
Example
roles = getml.data.Roles(
categorical=["col1", "col2"], target=["col3"]
)
df_expd = data.DataFrame.from_csv(
fnames=["file1.csv", "file2.csv"],
name="MY DATA FRAME",
sep=';',
quotechar='"',
roles=roles
)
columns property
unused property
column
Gets the role of a column by its column name.
PARAMETER | DESCRIPTION |
---|---|
colname | The name of the column. TYPE: |
RETURNS | DESCRIPTION |
---|---|
Role | The role of the column as a string. |
Source code in getml/data/roles/container.py
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 |
|
from_dict classmethod
Creates a roles object from a dictionary.
PARAMETER | DESCRIPTION |
---|---|
roles_dict | A dictionary where keys are role names and values are lists of column names. |
RETURNS | DESCRIPTION |
---|---|
Roles | A roles object. |
Source code in getml/data/roles/container.py
154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 |
|
from_mapping classmethod
Creates a roles object from a mapping of column names to roles.
PARAMETER | DESCRIPTION |
---|---|
roles_mapping | A dictionary where keys are column names and values are role names. |
RETURNS | DESCRIPTION |
---|---|
Roles | A roles object. |
Source code in getml/data/roles/container.py
176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 |
|
infer
Infers the role of a column by its name.
PARAMETER | DESCRIPTION |
---|---|
colname | The name of the column to be inferred. TYPE: |
RETURNS | DESCRIPTION |
---|---|
Role | The role of the column as a string. |
Source code in getml/data/roles/container.py
195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 |
|
to_dict
Expresses the roles object as a dictionary.
RETURNS | DESCRIPTION |
---|---|
Dict[Role, List[str]] | A dictionary where keys are role names and values are lists of column names. |
Source code in getml/data/roles/container.py
213 214 215 216 217 218 219 220 |
|
to_list
Returns a list containing the roles, without the corresponding columns names.
RETURNS | DESCRIPTION |
---|---|
List[Role] | A list where each element is a role name, repeated by the number of columns in that role. |
Source code in getml/data/roles/container.py
222 223 224 225 226 227 228 229 230 |
|
to_mapping
Maps column names to their roles.
RETURNS | DESCRIPTION |
---|---|
Dict[str, Role] | A dictionary where keys are column names and values are role names. |
Source code in getml/data/roles/container.py
232 233 234 235 236 237 238 239 |
|
update
Merges the roles of two roles objects.
PARAMETER | DESCRIPTION |
---|---|
other | The roles object to be merged with the current one. TYPE: |
RETURNS | DESCRIPTION |
---|---|
Roles | A new roles object containing the merged roles. |
Source code in getml/data/roles/container.py
251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 |
|
validate
validate() -> None
Checks if the roles are consistent.
RAISES | DESCRIPTION |
---|---|
ValueError | If the roles are inconsistent. |
Source code in getml/data/roles/container.py
270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 |
|