import microdf as mdf
import pandas as pd
import numpy as np# Create sample data
x = [10, 20, 30, 40, 100]
w = [1, 2, 3, 4, 5]
df = pd.DataFrame({"x": x, "w": w})Using MicroSeries.gini()¶
# Create a MicroSeries with weights
ms = mdf.MicroSeries(df.x, weights=df.w)
print(f"Gini coefficient: {ms.gini():.4f}")Without weights¶
# Create a MicroSeries without weights (equal weights)
ms_unweighted = mdf.MicroSeries(df.x)
print(f"Unweighted Gini coefficient: {ms_unweighted.gini():.4f}")Working with MicroDataFrame¶
# Create a MicroDataFrame
mdf_df = mdf.MicroDataFrame(df, weights="w")
# Access column as MicroSeries and calculate gini
print(f"Gini from MicroDataFrame column: {mdf_df.x.gini():.4f}")