updated chart definition
-from splink.charts import load_chart_definition, altair_if_installed_else_json
+from .charts import load_chart_definition, altair_if_installed_else_json
from pyspark.sql.functions import col, count, when
@@ -13,10 +13,11 @@ def missingness_chart(df):
"""
- # Load JSON chart definition
chart_path = "missingness_chart_def.json"
missingness_chart_def = load_chart_definition(chart_path)
+ # Data for plot
+
# Count and percentage of nulls in each columns as pandas dataframe
df_nulls = df.select([count(when(col(c).isNull(), c)).alias(c) for c in df.columns])
pd_nulls = df_nulls.toPandas()
@@ -26,4 +27,6 @@ def missingness_chart(df):
pd_nulls['percentage'] = round(pd_nulls['value']*100/ pd_nulls['record_count'], 1)
pd_nulls['percentage'] = pd_nulls['percentage'].astype(str) + "%"
- return altair_if_installed_else_json("missingness_chart_def.json")
\ No newline at end of file
+ missingness_chart_def["data"]["values"] = pd_nulls
+
+ return altair_if_installed_else_json(missingness_chart_def)
