ValueError ::无法从重复的轴错误重新索引

时间:2019-04-10 05:46:23

标签: python pandas indexing

我正在尝试用python编写函数。但是,它始终返回错误“无法从重复的轴重新索引”。我一直无法弄清楚为什么我会收到错误消息。

$ kubectl get pods --namespace kube-system
NAME                                    READY     STATUS    RESTARTS   AGE
coredns-fb8b8dccf-9z8v5                 1/1       Running   3          6h
coredns-fb8b8dccf-wdtpl                 1/1       Running   3          6h
etcd-minikube                           1/1       Running   1          6h
kube-addon-manager-minikube             1/1       Running   1          6h
kube-apiserver-minikube                 1/1       Running   1          6h
kube-controller-manager-minikube        1/1       Running   1          6h
kube-proxy-m4whq                        1/1       Running   0          2h
kube-scheduler-minikube                 1/1       Running   1          6h
kubernetes-dashboard-79dd6bfc48-5z9cx   1/1       Running   3          6h
storage-provisioner                     1/1       Running   3          6h
tiller-deploy-8458f6c667-wmv62          1/1       Running   1          4h

我认为给出错误的代码行是

db.collection.find(
 {$and:[
 {$and:[{"position.x":{$eq:30}},{"position.y":{$eq:40}}]},
 {$and:[{"position.x":{$eq:40}},{"position.y":{$eq:50}}]}
 ]}
)

我在这里要做的是确保在随机样本选择中出现不超过3个相同的memberid。

一旦我们删除了这一行代码,该函数就会起作用。我们尝试使用

修复它
def get_match_digital(Demo, Imp, imp_cap):
    df102 = []
    # Loop for running a simulation n times
    d1 = df_new
    impcap = imp_cap

    for x in range(1):
        # Randomly selecting n number of random rows which would be no. of impressions in this case

        f2 = d1.sample(Imp)
        # applying frequency capping after sample selection
        d = f2.assign(rn=f2.sort_values(['MemberId'], ascending=False).groupby(['MemberId']).cumcount() + 1).query('rn <= 3')

        a = 20000
        df42 = []
        for y in range(10):
            df = f2.iloc[:a]

            df32 = df.loc[(df['ageGroup25_54'] == Demo)].MemberId.nunique()

            a = a + a

            df42.append(df32)

        df102.append(df42)

    transposed2 = list(zip(*df102))
    avg2 = lambda items: float(sum(items)) / len(items)

    averages2 = list(map(avg2, transposed2))
    columns = ['reach']
    final = pd.DataFrame(columns=columns)
    final = final.assign(reach=averages2)
    final['Imp'] = 20000 * (final.index.values + 1)
    final['reachP'] = round(((final['reach'] / Imp) * 100), 2)
    return final

并通过重置索引

d = f2.assign(rn=f2.sort_values(['MemberId'], ascending=False).groupby(['MemberId']).cumcount() + 1).query('rn <= 3')

我希望有人可以帮助我弄清楚为什么我得到此错误并帮助解决问题。

非常感谢!

0 个答案:

没有答案