I have a pandas dataframe which I have wrangled a bit with multi-indexing and pivoting.
If I ask Ipython to print it to the screen (just by making a selection and hitting enter), it has lovely formatting, like so:
If I then write this to CSV, with a basic command:
pivoted.to_csv(filepath)
I get some rather ugly formatting, like so:
How might I write the CSV file with the same formatting as in the Ipython console (the format is also the same in a regular console, just without the fancy boxes)?
By that I mean the neat hierarchy of column headers and grouping of the 'cru_year' entries.