为什么我得到一个KeyError:' Level *** not found'

时间:2016-08-17 02:33:15

标签: pandas

运行以下代码

pd.concat([df.iloc[[n],:], df.drop(n, axis=0)], axis=0)

我收到了一个数据框'

enter image description here enter image description here

我想删除索引级日期,但<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.w3.org/1999/xhtml"> <xsl:output method="xml" encoding="UTF-8" doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN" doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" indent="yes"/> <xsl:template match="/job/surface"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> <title>Untitled Document</title> </head> <body> <table width="600" border="0" align="center" style="font-family:Arial, Helvetica, sans-serif;"> <tr><td><table width="100%"><tr><td width="60%" valign="bottom"> <table width="100%"><tr><td style="padding: 0px 0px 5px 0px; font-size:10px;"><xsl:value-of select="preheader[1]"/></td></tr> <xsl:for-each select="preheader[position() > 1]"> <tr><td style="padding: 0px 0px 5px 0px; font-size:10px;"><xsl:value-of select="."/></td></tr></xsl:for-each> </table></td> <td width="40%"><xsl:apply-templates select="brand"/></td></tr></table></td></tr> <xsl:apply-templates select="headline | subhead | bullet_level_1 | bullet_level_2 | body_copy | footnote | chart | logo | generic_image"/> </table> </body> </html> </xsl:template> <!--Add templates below to style each element...--> <xsl:template match="headline"><tr><td class="headline full" valign="top" style=" font-size:150%; font-weight:bold; color:#444444; padding-bottom:5px; padding-top:14px;"><xsl:apply-templates /></td></tr></xsl:template> <xsl:template match="subhead"><tr><td class="subhead" style="padding: 5px 0px 0px 0px; color: rgb(181,26,138); font-size: 115%;"><xsl:apply-templates /></td></tr></xsl:template> ... </xsl:stylesheet> 给我def afun(group): aa=len(group) group.sort_values(inplace=True) return pd.DataFrame({'score':np.arange(aa),'price':group}) df = pd.DataFrame({ 'stock':np.repeat( ['AAPL','GOOG','YHOO'], 3 ), 'date':np.tile( pd.date_range('5/5/2015', periods=3, freq='D'), 3 ), 'price':(np.random.randn(9).cumsum() + 10) , 'price2':(np.random.randn(9).cumsum() + 10)}) df = df.set_index(['stock','date']) agroupDf=df.groupby(level='date') tt=agroupDf['price'].apply(afun)

我很好,如何放弃第一次约会?

所有错误消息如下

tt.reset_index(level='date', drop=True,inplace=True)

1 个答案:

答案 0 :(得分:2)

您的错误不是KeyError: 'Level date not found',而是ValueError: The name date occurs multiple times, use a level number。正如错误所示:

tt.reset_index(level=2, drop=True,inplace=True)

会给你你想要的东西。

相关问题