我正在遵循Lynda教程,他们使用以下代码:
import pandas as pd
import seaborn
flights = seaborn.load_dataset('flights')
flights_indexed = flights.set_index(['year','month'])
flights_unstacked = flights_indexed.unstack()
flights_unstacked['passengers','total'] = flights_unstacked.sum(axis=1)
Run Code Online (Sandbox Code Playgroud)
它完美无缺.但是,在我的情况下,似乎代码没有编译,对于最后一行我一直收到错误.
TypeError:无法将项插入到尚未作为现有类别的CategoricalIndex中
我在视频中知道他们使用的是Python 2,但是因为我正在学习工作(使用Python 3),所以我有Python 3.我能够弄清楚的大多数差异,但是我无法弄清楚如何'total'用乘客的总和来创建这个新的列.