簡體   English   中英

小於或等於給TypeError的熊貓:無效的類型比較

[英]Pandas less than or equal to giving TypeError: invalid type comparison

我有4個基於要連續過濾我的熊貓數據框的列表

categoryList=['Parameter1', 'Parameter1', 'Parameter2', 'Parameter2']
conditionList=['b1', 'b41', 'm1', 'm2']
conditionDescList=['>', 'btn', '<=', 'btn']
conditionParamList=['1000', '2:3', '0.5', '0.1:0.3']

現在我正在嘗試下面的代碼,以基於categoryList從我的2個數據幀( df_custid_markerdf_custid_bp )中過濾行

        k =0
        for i in conditionDescList:
            if(categoryList[k]=='Parameter1'):
                if(i=='btn'):
                    arrValues=conditionParamList[k].split(":")
                    minVal=arrValues[0]
                    maxVal=arrValues[1]
                    df_custid_marker=df_custid_marker[(df_custid_marker[conditionList[k]] > minVal) & (df_custid_marker[conditionList[k]] < maxVal)]
                elif(i=='>'):
                    df_custid_marker=df_custid_marker[(df_custid_marker[conditionList[k]] > conditionParamList[k])]
                elif(i=='<'):
                    df_custid_marker=df_custid_marker[(df_custid_marker[conditionList[k]] < conditionParamList[k])]
                elif(i=='<='):
                    df_custid_marker=df_custid_marker[(df_custid_marker[conditionList[k]] < conditionParamList[k]) | (df_custid_marker[conditionList[k]] == conditionParamList[k])]
                elif(i=='>='):
                    df_custid_marker=df_custid_marker[(df_custid_marker[conditionList[k]] > conditionParamList[k]) | (df_custid_marker[conditionList[k]] == conditionParamList[k])]
                else:
                    df_custid_marker=df_custid_marker[(df_custid_marker[conditionList[k]] == conditionParamList[k])]
            k+=1


        k =0
        for i in conditionDescList:
            if(categoryList[k]=='Parameter2'):
                if(i=='btn'):
                    arrValues=conditionParamList[k].split(":")
                    minVal=arrValues[0]
                    maxVal=arrValues[1]
                    df_custid_bp=df_custid_bp[(df_custid_bp[conditionList[k]] > minVal) & (df_custid_bp[conditionList[k]] < maxVal)]
                elif(i=='>'):
                    df_custid_bp=df_custid_bp[(df_custid_bp[conditionList[k]] > conditionParamList[k])]
                elif(i=='<'):
                    df_custid_bp=df_custid_bp[(df_custid_bp[conditionList[k]] < conditionParamList[k])]
                elif(i=='<='):
                    df_custid_bp=df_custid_bp[(df_custid_bp[conditionList[k]] < conditionParamList[k]) | (df_custid_bp[conditionList[k]] == conditionParamList[k])]
                elif(i=='>='):
                    df_custid_bp=df_custid_bp[(df_custid_bp[conditionList[k]] > conditionParamList[k]) | (df_custid_bp[conditionList[k]] == conditionParamList[k])]
                else:
                    df_custid_bp=df_custid_bp[(df_custid_bp[conditionList[k]] == conditionParamList[k])]
            k+=1

現在,我在<= df_custid_marker=df_custid_marker[(df_custid_marker[conditionList[k]] < conditionParamList[k]) | (df_custid_marker[conditionList[k]] == conditionParamList[k])] df_custid_marker=df_custid_marker[(df_custid_marker[conditionList[k]] < conditionParamList[k]) | (df_custid_marker[conditionList[k]] == conditionParamList[k])]

raise TypeError("invalid type comparison")

問題是數據框列類型為float且列表為string

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM