Для цикла с несколькими условиями IF в Pandas

<p>Click the button to create a SELECT and an OPTION element.</p>

<button onclick="myFunction()">Try it</button>

<script>
    function myFunction() {
        var ele = document.createElement("SELECT");
        ele.setAttribute("id", "mySelect");  
        document.body.appendChild(ele);

        var values=["option0","option1","option2","option3"];
        // foreach the  values array 
        for(i in values){
            // i is  the index of values;
            // create option  item
            var item = document.createElement("option");
            item.setAttribute("value", values[i]);
            item.innerText=values[i]; 
            ele.appendChild(item); 
        } 

    }
</script>
1
задан pygo 19 January 2019 в 08:26
поделиться

2 ответа

Я считаю, что ваша проблема заключается в использовании if elif else следующим образом:

if any(df["DWWC"+str(i)] <=18.25):
// executes if confidion is true
elif any((df["DWWC"+str(i)] >  18.25) &  (df["DWWC"+str(i)] <= 36.5)):
// executes if first condition is false and second condition is true
else:
// executes if both condition are false

Поэтому, когда ваше первое условие выполнено, оно никогда не проверяет другие. Попробуйте изменить это на что-то вроде этого:

if any(df["DWWC"+str(i)] <=18.25):
// executes if first condition is true
if any((df["DWWC"+str(i)] >  18.25) &  (df["DWWC"+str(i)] <= 36.5)):
// executes if second condition is true, regardless of the first
else:
// all other if's are false
0
ответ дан Dor Shinar 19 January 2019 в 08:26
поделиться

Вы можете использовать numpy.select и для получения имен столбцов format:

for i in range (1980,2015,5):
    m1 = df["DWWC{}".format(i)] <=18.25
    #inverted m1 mask by ~
    m2 = ~m1 & (df["DWWC{}".format(i)] <= 36.5)
    a = (((10-33)/(5))*(df["DWWC{}".format(i)]-5))+10 
    b = ((10/(df.two-df.three))*(df["DWWC{}".format(i)]-df.three))+df.Three
    c = (((df.Three_value-6)/(df.three-5))*(df["DWWC{}".format(i)]-6

    df["MWTP{}".format(i)] = np.select([m1,m2],[a,b], default=c)
0
ответ дан jezrael 19 January 2019 в 08:26
поделиться
Другие вопросы по тегам:

Похожие вопросы: