src/datafun/app.py - Project script (example).
Author: Denise Case
Date: 2026-08
RUN:
Open this project folder in VS Code.
Open an integrated Terminal in the root project folder
and paste the following command.
uv run python -m datafun.app
DOMAIN: Penguins
Explore a dataset of penguins using a simple,
repeatable exploratory data analysis (EDA) process.
EDA:
Exploratory Data Analysis helps us understand a new dataset.
A simple EDA process is:
- LOAD the data.
- INSPECT the data.
- CHECK data quality.
- DESCRIBE numeric variables.
- VISUALIZE distributions.
- EXPLORE relationships.
- SUMMARIZE what you found.
- DISPLAY the visualizations.
DESIGN:
Use this file to document your analysis
and orchestrate the work.
The reusable functions that do the data work live in utils_eda.py.
Reusable visualization functions come from eda-vizkit.
We import functions and pass in what they need.
SKILLS:
This project illustrates several core Python and analytics skills:
- calling functions in another file
- passing information to functions
- working with pandas DataFrames
- exploratory data analysis
main
The main entry point where execution begins.
Returns:
Source code in src/datafun/app.py
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
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
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337 | def main() -> None:
"""The main entry point where execution begins.
Arguments:
None.
Returns:
None.
"""
log_header(LOG, "P04 - EXPLORATORY DATA ANALYSIS")
LOG.info("===================================")
LOG.info("START main()")
LOG.info("===================================")
LOG.info("-------------------------------")
LOG.info("01. LOAD the data.")
LOG.info("-------------------------------")
df: pd.DataFrame = load_data(
dataset_name=DATASET_NAME,
log=LOG,
)
LOG.info("-------------------------------")
LOG.info("02. INSPECT the data.")
LOG.info("-------------------------------")
inspection_string: str = inspect(
df=df,
grain=GRAIN,
log=LOG,
)
LOG.info(inspection_string)
LOG.info("-------------------------------")
LOG.info("03. CHECK data quality.")
LOG.info("-------------------------------")
# Call the imported function build_data_dictionary()
# to create a starter data dictionary.
# Pass in the df and the logger.
data_dictionary: pd.DataFrame = build_data_dictionary(
df=df,
log=LOG,
)
LOG.info(f"\n{data_dictionary}")
# Call the imported function get_missing_counts()
# to count missing values in each column.
# Pass in the df and the logger.
missing_counts: pd.Series = get_missing_counts(
df=df,
log=LOG,
)
LOG.info(f"\nMissing values:\n{missing_counts}")
# Call the imported function get_duplicate_count()
# to count duplicate rows.
# Pass in the df and the logger.
duplicate_count: int = get_duplicate_count(
df=df,
log=LOG,
)
LOG.info(f"Duplicate rows: {duplicate_count}")
# Call the imported function show_missing_values()
# to visualize missing values.
# Pass in the df.
# get back the Axes object so we can save the chart.
missing_ax = show_missing_values(df)
# Save the missing values chart to the designated directory.
save_chart(
missing_ax,
CHART_DIR / "missing-values.png",
)
LOG.info("-------------------------------")
LOG.info("04. DESCRIBE numeric variables.")
LOG.info("-------------------------------")
numeric_summary: pd.DataFrame = get_numeric_summary(
df=df,
numeric_columns=NUMERIC_COLUMNS,
log=LOG,
)
LOG.info(f"\n{numeric_summary}")
LOG.info("-------------------------------")
LOG.info("05. VISUALIZE distributions.")
LOG.info("-------------------------------")
# For each column in the list of numeric columns,
# call the imported function show_numeric_distribution()
# to visualize the distribution of the column.
for column in NUMERIC_COLUMNS:
numeric_ax = show_numeric_distribution(
df,
column=column,
)
# Save the numeric distribution chart to the designated directory.
save_chart(
numeric_ax,
CHART_DIR / f"{column}-distribution.png",
)
# For each column in the list of categorical columns,
# call the imported function show_categorical_distribution()
# to visualize the distribution of the column.
for column in CATEGORICAL_COLUMNS:
categorical_ax = show_categorical_distribution(df, column=column)
# Save the categorical distribution chart to the designated directory.
save_chart(
categorical_ax,
CHART_DIR / f"{column}-distribution.png",
)
LOG.info("-------------------------------")
LOG.info("06. EXPLORE relationships (e.g., between 2 numeric variables).")
LOG.info("-------------------------------")
# Call the imported function get_correlation()
# to compute the correlation between the two selected numeric variables.
# Pass in the df, the x column, the y column, and the log.
correlation: float = get_correlation(
df=df,
x=X_COLUMN,
y=Y_COLUMN,
log=LOG,
)
LOG.info(f"Correlation between {X_COLUMN} and {Y_COLUMN}: {correlation:.3f}")
# Call the imported function show_numeric_relationship()
# to visualize the relationship between two numeric variables.
# Pass in the df, the x column, the y column.
# It returns a Matplotlib Axes object representing the plot.
relationship_ax = show_numeric_relationship(
df,
x=X_COLUMN,
y=Y_COLUMN,
)
# CUSTOM: Analyst must customize the Matplotlib Axes object with a title and axis labels.
relationship_ax.set_title("Penguin Flipper Length vs. Body Mass")
relationship_ax.set_xlabel("Flipper Length (mm)")
relationship_ax.set_ylabel("Body Mass (g)")
save_chart(
relationship_ax,
CHART_DIR / "one-relationship.png",
)
LOG.info("-------------------------------")
LOG.info("07. SUMMARIZE what you found.")
LOG.info("-------------------------------")
# Run this app first.
# Get some insights into data.
# After seeing the information, record your CUSTOM observations
# in a simple multi-line (triple-quoted) raw string (see the leading `r`).
LOG.info(r"""CUSTOM OBSERVATIONS:
The dataset contains penguin measurements.
Some observations (rows) are complete, but some are missing values.
I reviewed the relationship between:
Flipper length vs. body mass
and it shows a positive relationship.
Based on this EDA, I would next like to review additional
relationships between other numeric variables.
Marimo (reactive notebook cells) might be a good choice
for additional exploration.
""")
LOG.info("-------------------------------")
LOG.info("08. DISPLAY the charts.")
LOG.info("-------------------------------")
# eda-vizkit just returns Matplotlib Axes objects.
# The client (like this script or a marimo notebook),
# determines how and when to display the plots).
LOG.info("In a script, call plt.show() at the end to display all charts.")
LOG.info("Close all chart windows (with the close button) to continue.")
plt.show()
LOG.info("===================================")
LOG.info("END main() - Executed successfully!")
LOG.info("===================================")
|