experiments-d3/inequality/cleaning/clean.py
2024-12-16 23:22:42 -06:00

16 lines
350 B
Python

import polars as pl
# Load the CSV
df = pl.read_csv("dfa-networth-levels.csv")
# Select only the columns you want to keep: Date, Category, and Net worth
df_selected = df.select(["Date", "Category", "Net worth"])
melted_df = df_selected.pivot(
index=["Date"],
values=["Net worth"],
on=["Category"],
)
melted_df.write_csv("levels.csv")