I'm a newbie in Python, and currently trying to repeat examples from the books and courses. And in all cases I'm quite a lot struggling with DataFrame structure, it seems like it has been hugely changed from 2.7 to 3.0
Basically, in the current example, I want to add a total column (total for each year). so I've done the following
import pandas as pd
import seaborn
flights = seaborn.load_dataset('flights')
flights_indexed = flights.set_index(['year','month'])
flights_unstacked = flights_indexed.unstack();
from the example, the following line should work, but it doesn't in python3
flights_unstacked['passengers','total'] = flights_unstacked.sum(axis=1)
I found a few links that show how to add the column (link1, link2), but none of this work for me
flights_unstacked["passengers"].insert(loc=0,column="total", value=flights_unstacked.sum(axis=1).values)
In both cases, the error is the same cannot insert an item into a CategoricalIndex that is not already an existing category
I have a feeling that it must be something more tricky as my DataFrame no more completely flat, it's currently grouped and I want to add the total values precisely on the "month" level.
I would be super happy even if someone let me know how to google it!