我有一个看起来像this的数据框。
此处提供的数据包括3,000多家接受联邦医疗保险住院患者预期付款系统(IPPS)付款的美国超过3,000家医院的前100个最常开具账单的出院费用,这些费用是根据2011财年(FY)的联邦医疗保险严重程度诊断相关组(MS-DRG)根据每次出院费率支付的。
我在dataframe上执行了以下命令,以获得总排放的前两个记录:
dataframe_1 = dataframe.groupby('Provider Id').sum()
dataframe_1.nlargest(2,'Total Discharges')我收到如下错误:
C:\Users\user\Anaconda2\lib\site-packages\pandas\core\indexes\base.pyc in get_loc(self, key, method, tolerance)
2393 return self._engine.get_loc(key)
2394 except KeyError:
-> 2395 return self._engine.get_loc(self._maybe_cast_indexer(key))
2396
2397 indexer = self.get_indexer([key], method=method, tolerance=tolerance)
pandas\_libs\index.pyx in pandas._libs.index.IndexEngine.get_loc (pandas\_libs\index.c:5239)()
pandas\_libs\index.pyx in pandas._libs.index.IndexEngine.get_loc (pandas\_libs\index.c:5085)()
pandas\_libs\hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item (pandas\_libs\hashtable.c:20405)()
pandas\_libs\hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item (pandas\_libs\hashtable.c:20359)()
KeyError: 'Total Discharges'欢迎对错误的理解提供任何帮助!
发布于 2017-07-26 23:05:49
dataframe_1 = dataframe.groupby('Provider Id', as_index=False).sum()
dataframe_1.nlargest(2,'Total Discharges')VinceP已经指出了正确的根本原因
https://stackoverflow.com/questions/45325353
复制相似问题