Having an issue appending to list inside functionHow do I check if a list is empty?Finding the index of an item given a list containing it in PythonDifference between append vs. extend list methods in Pythonvar functionName = function() vs function functionName() How to append something to an array?Does Python have a ternary conditional operator?How to make a flat list out of list of lists?How to clone or copy a list?How do I list all files of a directory?Does Python have a string 'contains' substring method?

"You are your self first supporter", a more proper way to say it

Is it legal for company to use my work email to pretend I still work there?

Maximum likelihood parameters deviate from posterior distributions

Why doesn't H₄O²⁺ exist?

How to determine what difficulty is right for the game?

Do infinite dimensional systems make sense?

Could an aircraft fly or hover using only jets of compressed air?

RSA: Danger of using p to create q

Approximately how much travel time was saved by the opening of the Suez Canal in 1869?

Rock identification in KY

LaTeX: Why are digits allowed in environments, but forbidden in commands?

Is it inappropriate for a student to attend their mentor's dissertation defense?

What does it mean to describe someone as a butt steak?

Convert two switches to a dual stack, and add outlet - possible here?

Cross compiling for RPi - error while loading shared libraries

A newer friend of my brother's gave him a load of baseball cards that are supposedly extremely valuable. Is this a scam?

What is a clear way to write a bar that has an extra beat?

Paid for article while in US on F-1 visa?

Can a Cauchy sequence converge for one metric while not converging for another?

DC-DC converter from low voltage at high current, to high voltage at low current

Why can't we play rap on piano?

Why can't I see bouncing of switch on oscilloscope screen?

meaning of に in 本当に?

How do I deal with an unproductive colleague in a small company?



Having an issue appending to list inside function


How do I check if a list is empty?Finding the index of an item given a list containing it in PythonDifference between append vs. extend list methods in Pythonvar functionName = function() vs function functionName() How to append something to an array?Does Python have a ternary conditional operator?How to make a flat list out of list of lists?How to clone or copy a list?How do I list all files of a directory?Does Python have a string 'contains' substring method?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








1















I have the following table that has a unique ID, actual, and modeled output.



 Pass_ID Actual Modeled 
0 100 1 1
1 101 0 1
2 102 1 0
3 103 1 1


I wrote the following function so I can generate a list which eventually I'll turn into a dataframe so I can easily call back the rows for each Pass_ID to see if I can isolate why the model is not working for those rows. However, the list keeps coming back empty.



new_list = []

def isolate_diff(df):
if df['Modeled'].any() != df['Actual'].any():
new_list.appened(df['Pass_ID'])
else:
pass

return new_list


How can I fix this issue?










share|improve this question
























  • Your code is incorrect. It should be append instead of appened in line 5.

    – Yusufsn
    Mar 8 at 2:04











  • You never call your isolate_diff(df) function. Try adding new_list = isolate_diff(df) to the bottom of your script

    – Reedinationer
    Mar 8 at 2:05











  • It is better to define new_list in isolate_diff because the function will return new_list.

    – Ellisein
    Mar 8 at 2:08

















1















I have the following table that has a unique ID, actual, and modeled output.



 Pass_ID Actual Modeled 
0 100 1 1
1 101 0 1
2 102 1 0
3 103 1 1


I wrote the following function so I can generate a list which eventually I'll turn into a dataframe so I can easily call back the rows for each Pass_ID to see if I can isolate why the model is not working for those rows. However, the list keeps coming back empty.



new_list = []

def isolate_diff(df):
if df['Modeled'].any() != df['Actual'].any():
new_list.appened(df['Pass_ID'])
else:
pass

return new_list


How can I fix this issue?










share|improve this question
























  • Your code is incorrect. It should be append instead of appened in line 5.

    – Yusufsn
    Mar 8 at 2:04











  • You never call your isolate_diff(df) function. Try adding new_list = isolate_diff(df) to the bottom of your script

    – Reedinationer
    Mar 8 at 2:05











  • It is better to define new_list in isolate_diff because the function will return new_list.

    – Ellisein
    Mar 8 at 2:08













1












1








1








I have the following table that has a unique ID, actual, and modeled output.



 Pass_ID Actual Modeled 
0 100 1 1
1 101 0 1
2 102 1 0
3 103 1 1


I wrote the following function so I can generate a list which eventually I'll turn into a dataframe so I can easily call back the rows for each Pass_ID to see if I can isolate why the model is not working for those rows. However, the list keeps coming back empty.



new_list = []

def isolate_diff(df):
if df['Modeled'].any() != df['Actual'].any():
new_list.appened(df['Pass_ID'])
else:
pass

return new_list


How can I fix this issue?










share|improve this question
















I have the following table that has a unique ID, actual, and modeled output.



 Pass_ID Actual Modeled 
0 100 1 1
1 101 0 1
2 102 1 0
3 103 1 1


I wrote the following function so I can generate a list which eventually I'll turn into a dataframe so I can easily call back the rows for each Pass_ID to see if I can isolate why the model is not working for those rows. However, the list keeps coming back empty.



new_list = []

def isolate_diff(df):
if df['Modeled'].any() != df['Actual'].any():
new_list.appened(df['Pass_ID'])
else:
pass

return new_list


How can I fix this issue?







python list function append






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 8 at 2:27









Pikachu the Purple Wizard

2,03061429




2,03061429










asked Mar 8 at 2:01









Ryan SullivanRyan Sullivan

82




82












  • Your code is incorrect. It should be append instead of appened in line 5.

    – Yusufsn
    Mar 8 at 2:04











  • You never call your isolate_diff(df) function. Try adding new_list = isolate_diff(df) to the bottom of your script

    – Reedinationer
    Mar 8 at 2:05











  • It is better to define new_list in isolate_diff because the function will return new_list.

    – Ellisein
    Mar 8 at 2:08

















  • Your code is incorrect. It should be append instead of appened in line 5.

    – Yusufsn
    Mar 8 at 2:04











  • You never call your isolate_diff(df) function. Try adding new_list = isolate_diff(df) to the bottom of your script

    – Reedinationer
    Mar 8 at 2:05











  • It is better to define new_list in isolate_diff because the function will return new_list.

    – Ellisein
    Mar 8 at 2:08
















Your code is incorrect. It should be append instead of appened in line 5.

– Yusufsn
Mar 8 at 2:04





Your code is incorrect. It should be append instead of appened in line 5.

– Yusufsn
Mar 8 at 2:04













You never call your isolate_diff(df) function. Try adding new_list = isolate_diff(df) to the bottom of your script

– Reedinationer
Mar 8 at 2:05





You never call your isolate_diff(df) function. Try adding new_list = isolate_diff(df) to the bottom of your script

– Reedinationer
Mar 8 at 2:05













It is better to define new_list in isolate_diff because the function will return new_list.

– Ellisein
Mar 8 at 2:08





It is better to define new_list in isolate_diff because the function will return new_list.

– Ellisein
Mar 8 at 2:08












3 Answers
3






active

oldest

votes


















1














I agree with @Prune, but to solve it, i think you need a whole different solution:



print(df[df['Modeled']!=df['Actual']])


Output:



 Pass_ID Actual Modeled
1 101 0 1
2 102 1 0


If you want a list of Pass_ID:



print(df.loc[df['Modeled']!=df['Actual'],'Pass_ID'].tolist())


Output:



[101, 102]





share|improve this answer


















  • 1





    wow. that's awesome. thanks so much. I think I over though it. really appreciate everyone's help

    – Ryan Sullivan
    Mar 8 at 4:35


















0














You wrote a global condition, not a vectorized condition:



if df['Modeled'].any() != df['Actual'].any():


Each term is True if any element is 1. This evaluates quickly to



if True != True


which gets you an empty new_list.



Instead, write an expression grabbing df['Pass_ID'], filtered where df['Modeled'] != df['Actual']. Can you take it from there?






share|improve this answer






























    0














    Change new_list.appened(df['Pass_ID']) to new_list.append(df['Pass_ID'])



    Edit: Prune and U9 detected a few other errors. This was the first incorrect thing I saw. Please defer to their answers for more detailed revisions






    share|improve this answer

























    • That's not all tho...

      – U9-Forward
      Mar 8 at 2:15











    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55055696%2fhaving-an-issue-appending-to-list-inside-function%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    3 Answers
    3






    active

    oldest

    votes








    3 Answers
    3






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    I agree with @Prune, but to solve it, i think you need a whole different solution:



    print(df[df['Modeled']!=df['Actual']])


    Output:



     Pass_ID Actual Modeled
    1 101 0 1
    2 102 1 0


    If you want a list of Pass_ID:



    print(df.loc[df['Modeled']!=df['Actual'],'Pass_ID'].tolist())


    Output:



    [101, 102]





    share|improve this answer


















    • 1





      wow. that's awesome. thanks so much. I think I over though it. really appreciate everyone's help

      – Ryan Sullivan
      Mar 8 at 4:35















    1














    I agree with @Prune, but to solve it, i think you need a whole different solution:



    print(df[df['Modeled']!=df['Actual']])


    Output:



     Pass_ID Actual Modeled
    1 101 0 1
    2 102 1 0


    If you want a list of Pass_ID:



    print(df.loc[df['Modeled']!=df['Actual'],'Pass_ID'].tolist())


    Output:



    [101, 102]





    share|improve this answer


















    • 1





      wow. that's awesome. thanks so much. I think I over though it. really appreciate everyone's help

      – Ryan Sullivan
      Mar 8 at 4:35













    1












    1








    1







    I agree with @Prune, but to solve it, i think you need a whole different solution:



    print(df[df['Modeled']!=df['Actual']])


    Output:



     Pass_ID Actual Modeled
    1 101 0 1
    2 102 1 0


    If you want a list of Pass_ID:



    print(df.loc[df['Modeled']!=df['Actual'],'Pass_ID'].tolist())


    Output:



    [101, 102]





    share|improve this answer













    I agree with @Prune, but to solve it, i think you need a whole different solution:



    print(df[df['Modeled']!=df['Actual']])


    Output:



     Pass_ID Actual Modeled
    1 101 0 1
    2 102 1 0


    If you want a list of Pass_ID:



    print(df.loc[df['Modeled']!=df['Actual'],'Pass_ID'].tolist())


    Output:



    [101, 102]






    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Mar 8 at 2:11









    U9-ForwardU9-Forward

    17.9k51743




    17.9k51743







    • 1





      wow. that's awesome. thanks so much. I think I over though it. really appreciate everyone's help

      – Ryan Sullivan
      Mar 8 at 4:35












    • 1





      wow. that's awesome. thanks so much. I think I over though it. really appreciate everyone's help

      – Ryan Sullivan
      Mar 8 at 4:35







    1




    1





    wow. that's awesome. thanks so much. I think I over though it. really appreciate everyone's help

    – Ryan Sullivan
    Mar 8 at 4:35





    wow. that's awesome. thanks so much. I think I over though it. really appreciate everyone's help

    – Ryan Sullivan
    Mar 8 at 4:35













    0














    You wrote a global condition, not a vectorized condition:



    if df['Modeled'].any() != df['Actual'].any():


    Each term is True if any element is 1. This evaluates quickly to



    if True != True


    which gets you an empty new_list.



    Instead, write an expression grabbing df['Pass_ID'], filtered where df['Modeled'] != df['Actual']. Can you take it from there?






    share|improve this answer



























      0














      You wrote a global condition, not a vectorized condition:



      if df['Modeled'].any() != df['Actual'].any():


      Each term is True if any element is 1. This evaluates quickly to



      if True != True


      which gets you an empty new_list.



      Instead, write an expression grabbing df['Pass_ID'], filtered where df['Modeled'] != df['Actual']. Can you take it from there?






      share|improve this answer

























        0












        0








        0







        You wrote a global condition, not a vectorized condition:



        if df['Modeled'].any() != df['Actual'].any():


        Each term is True if any element is 1. This evaluates quickly to



        if True != True


        which gets you an empty new_list.



        Instead, write an expression grabbing df['Pass_ID'], filtered where df['Modeled'] != df['Actual']. Can you take it from there?






        share|improve this answer













        You wrote a global condition, not a vectorized condition:



        if df['Modeled'].any() != df['Actual'].any():


        Each term is True if any element is 1. This evaluates quickly to



        if True != True


        which gets you an empty new_list.



        Instead, write an expression grabbing df['Pass_ID'], filtered where df['Modeled'] != df['Actual']. Can you take it from there?







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Mar 8 at 2:08









        PrunePrune

        45.8k143559




        45.8k143559





















            0














            Change new_list.appened(df['Pass_ID']) to new_list.append(df['Pass_ID'])



            Edit: Prune and U9 detected a few other errors. This was the first incorrect thing I saw. Please defer to their answers for more detailed revisions






            share|improve this answer

























            • That's not all tho...

              – U9-Forward
              Mar 8 at 2:15















            0














            Change new_list.appened(df['Pass_ID']) to new_list.append(df['Pass_ID'])



            Edit: Prune and U9 detected a few other errors. This was the first incorrect thing I saw. Please defer to their answers for more detailed revisions






            share|improve this answer

























            • That's not all tho...

              – U9-Forward
              Mar 8 at 2:15













            0












            0








            0







            Change new_list.appened(df['Pass_ID']) to new_list.append(df['Pass_ID'])



            Edit: Prune and U9 detected a few other errors. This was the first incorrect thing I saw. Please defer to their answers for more detailed revisions






            share|improve this answer















            Change new_list.appened(df['Pass_ID']) to new_list.append(df['Pass_ID'])



            Edit: Prune and U9 detected a few other errors. This was the first incorrect thing I saw. Please defer to their answers for more detailed revisions







            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Mar 8 at 2:24

























            answered Mar 8 at 2:09









            alec935alec935

            945624




            945624












            • That's not all tho...

              – U9-Forward
              Mar 8 at 2:15

















            • That's not all tho...

              – U9-Forward
              Mar 8 at 2:15
















            That's not all tho...

            – U9-Forward
            Mar 8 at 2:15





            That's not all tho...

            – U9-Forward
            Mar 8 at 2:15

















            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55055696%2fhaving-an-issue-appending-to-list-inside-function%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            1928 у кіно

            Захаров Федір Захарович

            Ель Греко