face2face.imports.load_all_data.Data.replace_str_attr_to_float¶
-
Data.
replace_str_attr_to_float
()¶ Replace string attribute values
Replaces string attributes into float attributes for the null model functions.
- Parameters
self (Data) – Data Object that contains Tij- and Metadata for a data set.
- Returns
self – Data Object that contains Tij- and Metadata for a data set. Metadata string attribute values are changed into float values.
- Return type
Examples
As you can see in this example every non-numerical or NaN value gets replaced into a float value. In this case “F” turns into 0.0 and “M” turns into 1.0.
>>> attr_list = ["ID", "Age", "Sex"] >>> test_df = Data(path_tij="face2face/data/Test/tij_test.dat", separator_tij=" ", >>> path_meta="face2face/data/Test/meta_test.dat", separator_meta=" ", >>> meta_attr_list=attr_list) >>> print(test_df.metadata) ID Age Sex Index 0 0 1.00000 F 1 1 0.00000 NaN 2 2 nan M 3 3 0.00000 F 4 4 nan M 5 6 1.00000 F 6 7 1.00000 NaN 7 10 2.00000 F 8 11 2.00000 M 9 12 2.00000 F >>> test_df.replace_str_attr_to_float() >>> print(test_df.metadata) ID Age Sex Index 0 0 1.00000 0.00000 1 1 0.00000 NaN 2 2 NaN 1.00000 3 3 0.00000 0.00000 4 4 NaN 1.00000 5 6 1.00000 0.00000 6 7 1.00000 NaN 7 10 2.00000 0.00000 8 11 2.00000 1.00000 9 12 2.00000 0.00000