Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/295.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python “不知道如何解决”;索引器:索引0超出大小为0的轴0的界限;_Python_Pandas - Fatal编程技术网

Python “不知道如何解决”;索引器:索引0超出大小为0的轴0的界限;

Python “不知道如何解决”;索引器:索引0超出大小为0的轴0的界限;,python,pandas,Python,Pandas,我有下表: 样本数据: e_id e_ctry e_grp_id e_loc_nbr e_loc_id e_sal ============================================= 111 03 65 889 03 10000 131 01 67 009 09 8000 152 02 12 545 09 17000 155 04

我有下表:

样本数据:

e_id e_ctry e_grp_id e_loc_nbr e_loc_id e_sal
=============================================
111  03     65       889        03      10000
131  01     67       009        09      8000
152  02     12       545        09      17000
155  04     55       778        09      33000
115  04     55       778        09      33000
156  04     55       778        09      33000 
177  03     65       889        03      14000
122  03     65       889        03      14000
141  03     65       889        03      17000
171  03     65       889        03      14000
正在尝试以下代码:

d_tbl = self.emp_d[['e_id','e_ctry','e_grp_id','e_loc_nbr','e_loc_id','e_sal']].drop_duplicates()


def e_c_rslt(self):
    e_c_data = self.d_tbl[(self.d_tbl['e_loc_id']==1) ][['e_id','e_ctry','e_grp_id','e_loc_nbr','e_sal']]
    e_c_grpd = e_c_data.groupby([e_id','e_grp_id','e_ctry']).e_sal.nunique().reset_index() 
    rslt_ac9b=e_c_grpd[e_c_grpd.e_sal>15000] 
但请继续获取以下错误消息:

e_c_grpd = e_c_data.groupby([e_id','e_grp_id','e_ctry']).e_sal.nunique().reset_index() 

File "/usr/local/lib/python2.7/dist-packages/pandas/core/groupby.py", line 2866, in nunique
    res = out if ids[0] != -1 else out[1:]
IndexError: index 0 is out of bounds for axis 0 with size 0
不明白我做错了什么

预期O/p:

e_id e_ctry e_grp_id  e_sal
===========================
111  03     65       10000
177  03     65       14000
122  03     65       14000
141  03     65       17000
171  03     65       14000
如果
e\u sal>15000
以及同一
'e\u-ctry',e\u-grp\u-id'.
存在不同的
e\u-sal
,则要求收集
['e\u-id',e\u-grp\u-id'.

更新1:

打印后
打印(e\u c\u数据)
获取:

Empty DataFrame
Columns: [e_id,e_ctry,e_grp_id,e_loc_nbr,e_sal]
Index: []

该错误消息告诉您要索引的对象的大小为0——换句话说,它是空的。为什么它是空的?好吧,你可以输入
print
s来找出它发生的地方,或者我们可以只看一下你的相框:

e_id e_ctry e_grp_id e_loc_nbr e_loc_id e_sal
=============================================
111  03     65       889        03      10000
131  01     67       009        09      8000
假设这是代表性的,请注意您的e_loc_id列以0开头。但如果它是一个整数,它就不会:那些显示时没有前导零。这意味着您必须具有字符串:

In [13]: df = pd.DataFrame({"A": [1,2], "B": ['01', '02']})

In [14]: df
Out[14]: 
   A   B
0  1  01
1  2  02

In [15]: df.dtypes
Out[15]: 
A     int64
B    object
dtype: object
但如果您的e_loc_d是字符串,则此比较将永远不会成功:

self.d_tbl['e_loc_id']==1

因此e_c_数据是空的。

需要什么输出?@U9 Forward更新了这个问题。非常感谢。用结果更新了我的问题。