|
43 | 43 | TableReport(employees_df) |
44 | 44 |
|
45 | 45 | # %% |
46 | | -# |
47 | 46 | # You can use the interactive display above to explore the dataset visually. |
48 | 47 | # |
| 48 | +# It is also possible to tell skrub to replace the default pandas & polars |
| 49 | +# displays with |TableReport| by modifying the global config with |
| 50 | +# |set_config|. |
| 51 | +# |
49 | 52 | # .. note:: |
50 | 53 | # |
51 | 54 | # You can see a few more `example reports`_ online. We also |
|
72 | 75 | employees_df = Cleaner().fit_transform(employees_df) |
73 | 76 | TableReport(employees_df) |
74 | 77 |
|
75 | | -# %% |
76 | | -# It is also possible to tell skrub to replace the default pandas & polars |
77 | | -# displays with |TableReport| by modifying the global config with |
78 | | -# |set_config|. |
79 | | - |
80 | | -from skrub import set_config |
81 | | - |
82 | | -set_config(use_table_report=True) |
83 | | - |
84 | | -employees_df |
85 | | - |
86 | | -# %% |
87 | | -# This setting can easily be reverted: |
88 | | - |
89 | | -set_config(use_table_report=False) |
90 | | - |
91 | | -employees_df |
92 | | - |
93 | 78 | # %% |
94 | 79 | # Easily building a strong baseline for tabular machine learning |
95 | 80 | # -------------------------------------------------------------- |
|
117 | 102 | # :ref:`user_guide_tabular_pipeline`. |
118 | 103 |
|
119 | 104 |
|
120 | | -# %% |
121 | | -# Assembling data |
122 | | -# --------------- |
123 | | -# |
124 | | -# Skrub allows imperfect assembly of data, such as joining dataframes |
125 | | -# on columns that contain typos. Skrub's joiners have ``fit`` and |
126 | | -# ``transform`` methods, storing information about the data across calls. |
127 | | -# |
128 | | -# The |Joiner| allows fuzzy-joining multiple tables, where each row of |
129 | | -# a main table will be augmented with values from the best match in the auxiliary table. |
130 | | -# You can control how distant fuzzy-matches are allowed to be with the |
131 | | -# ``max_dist`` parameter. |
132 | | - |
133 | | -# %% |
134 | | -# In the following, we add information about countries to a table containing |
135 | | -# airports and the cities they are in: |
136 | | - |
137 | | -# %% |
138 | | -import pandas as pd |
139 | | - |
140 | | -from skrub import Joiner |
141 | | - |
142 | | -airports = pd.DataFrame( |
143 | | - { |
144 | | - "airport_id": [1, 2], |
145 | | - "airport_name": ["Charles de Gaulle", "Aeroporto Leonardo da Vinci"], |
146 | | - "city": ["Paris", "Roma"], |
147 | | - } |
148 | | -) |
149 | | -# Notice the "Rome" instead of "Roma" |
150 | | -capitals = pd.DataFrame( |
151 | | - {"capital": ["Berlin", "Paris", "Rome"], "country": ["Germany", "France", "Italy"]} |
152 | | -) |
153 | | -joiner = Joiner( |
154 | | - capitals, |
155 | | - main_key="city", |
156 | | - aux_key="capital", |
157 | | - max_dist=0.8, |
158 | | - add_match_info=False, |
159 | | -) |
160 | | -joiner.fit_transform(airports) |
161 | | - |
162 | | -# %% |
163 | | -# Information about countries has been added, even if the rows aren't exactly matching. |
164 | | -# |
165 | | -# Skrub allows you to aggregate multiple tables according to various strategies. You |
166 | | -# can see other ways to join multiple tables in :ref:`user_guide_joining_dataframes`. |
167 | | - |
168 | 105 | # %% |
169 | 106 | # Encoding any data as numerical features |
170 | 107 | # --------------------------------------- |
|
241 | 178 | # provided by skrub, and :ref:`sphx_glr_auto_examples_01_encodings.py` for a |
242 | 179 | # comparison between the different methods. |
243 | 180 |
|
| 181 | +# %% |
| 182 | +# Assembling data |
| 183 | +# --------------- |
| 184 | +# |
| 185 | +# Skrub allows imperfect assembly of data, such as joining dataframes |
| 186 | +# on columns that contain typos. Skrub's joiners have ``fit`` and |
| 187 | +# ``transform`` methods, storing information about the data across calls. |
| 188 | +# |
| 189 | +# The |Joiner| allows fuzzy-joining multiple tables, where each row of |
| 190 | +# a main table will be augmented with values from the best match in the auxiliary table. |
| 191 | +# You can control how distant fuzzy-matches are allowed to be with the |
| 192 | +# ``max_dist`` parameter. |
| 193 | + |
| 194 | +# %% |
| 195 | +# In the following, we add information about countries to a table containing |
| 196 | +# airports and the cities they are in: |
| 197 | + |
| 198 | +# %% |
| 199 | +import pandas as pd |
| 200 | + |
| 201 | +from skrub import Joiner |
| 202 | + |
| 203 | +airports = pd.DataFrame( |
| 204 | + { |
| 205 | + "airport_id": [1, 2], |
| 206 | + "airport_name": ["Charles de Gaulle", "Aeroporto Leonardo da Vinci"], |
| 207 | + "city": ["Paris", "Roma"], |
| 208 | + } |
| 209 | +) |
| 210 | +# Notice the "Rome" instead of "Roma" |
| 211 | +capitals = pd.DataFrame( |
| 212 | + {"capital": ["Berlin", "Paris", "Rome"], "country": ["Germany", "France", "Italy"]} |
| 213 | +) |
| 214 | +joiner = Joiner( |
| 215 | + capitals, |
| 216 | + main_key="city", |
| 217 | + aux_key="capital", |
| 218 | + max_dist=0.8, |
| 219 | + add_match_info=False, |
| 220 | +) |
| 221 | +joiner.fit_transform(airports) |
| 222 | + |
| 223 | +# %% |
| 224 | +# Information about countries has been added, even if the rows aren't exactly matching. |
| 225 | +# |
| 226 | +# Skrub allows you to aggregate multiple tables according to various strategies. You |
| 227 | +# can see other ways to join multiple tables in :ref:`user_guide_joining_dataframes`. |
| 228 | + |
244 | 229 | # %% |
245 | 230 | # Advanced use cases |
246 | 231 | # ---------------------- |
|
0 commit comments