Data Wrangling with Pandas

Randy Widialaksono · June 1, 2020

Multi-index column headers

Having multi-index columns restricts what you can do in Pandas. For instance, we can’t use pd.query, and writing functions for pd.apply, pd.groupby becomes complicated. Moving forward I would opt to temporarily join the rows with an appropriate delimiter, and expand when exporting. Or just select one row as header when possible.

Exporting multi-index columns to CSV

I’ve encountered an occasion where Pandas dumped tuples instead of two/multiple rows of headers. Rounding before saving (df.round().to_csv()) somehow fixes it.

Code snippets and other tips to follow.

Twitter, Facebook