Created
August 9, 2025 20:06
-
-
Save anapaulagomes/9c7f23d7dc27fc9b86ef18e336d9e552 to your computer and use it in GitHub Desktop.
Plotly and polars
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 100% stacked bar of null vs not-null values | |
_proportion = [] | |
for _col, _valid, _nulls in zip(raw_df.columns, raw_df.count(), raw_df.null_count()): | |
_total = _valid[0] + _nulls[0] | |
_not_null = _valid[0]/_total | |
_nulls = _nulls[0]/_total | |
_proportion.append({"column": _col, "status": "not-null", "proportion": _not_null}) | |
_proportion.append({"column": _col, "status": "null", "proportion": _nulls}) | |
print(f"{_col} not-null {_not_null:.2f}% null {_nulls:.2f}%") | |
_fig = px.bar( | |
pl.DataFrame(_proportion), | |
x="column", | |
y="proportion", | |
color="status", | |
barmode="stack", | |
title="Null vs non-null values per column" | |
) | |
_fig.update_layout(yaxis_tickformat=".0%") | |
_fig |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment