python pandas: assigning a json data to a data frame entry returns error “Incompatible indexer with...












0















As a newbie to python I'm struggling with an error "Incompatible indexer with Series".



I'm reading a entry from a postgreSQL database:



    df_postgresDB = pd.read_sql_query('SELECT * FROM public.json_view',con=<...>)        
exampleKey = 'FPB-83160'
jsonCol = 'efforts'
AreasDict = df_postgresDB.loc[exampleKey, jsonCol]
print('AreasDict=', AreasDict)
print('type(AreasDict)=', type(AreasDict))


...output:



    AreasDict= {'4G NeVe': 0, '4G FT ET': 400, '4G C-Plane': 800, 'MANO BTSSM': 0}
type(AreasDict)= <class 'dict'>


The column in the postgreSQL data base shows type 'jsonb':



enter image description here



This 'AreasDict' is used in the function of another project I want to call and re-use for my project. But in my project, I need to build up the data from another source. So I create a data frame and try to assign that 'AreasDict' ()...



    column_names = ['issue_key', jsonCol]
df = pd.DataFrame(index=range(1,2), columns=column_names)
df.iloc[0, 0] = exampleKey
df.iloc[0, 1] = AreasDict


... and with the last code line I get that error




ValueError: Incompatible indexer with Series




What do I do wrong?










share|improve this question




















  • 1





    Problem is in pandas is not recomended store dicts in DataFrame column, but one possible solution is use df.iloc[0, 1] = [AreasDict]

    – jezrael
    Nov 20 '18 at 9:04











  • Yes, that turns it into class 'list' !! I'll try that in my project that calls the function using it and let you know.

    – Joe Phi
    Nov 20 '18 at 9:09













  • So it working for you nice? It is what you need?

    – jezrael
    Nov 20 '18 at 9:10








  • 1





    I still have to try that principle in my 'real' project that calls the shared function and see if that function eats it.Will let you know.

    – Joe Phi
    Nov 20 '18 at 9:11






  • 1





    the workaround? this one: if isinstance(AreasDict, str) : then AreasDict = ast.literal_eval(AreasDict

    – Joe Phi
    Nov 20 '18 at 13:51
















0















As a newbie to python I'm struggling with an error "Incompatible indexer with Series".



I'm reading a entry from a postgreSQL database:



    df_postgresDB = pd.read_sql_query('SELECT * FROM public.json_view',con=<...>)        
exampleKey = 'FPB-83160'
jsonCol = 'efforts'
AreasDict = df_postgresDB.loc[exampleKey, jsonCol]
print('AreasDict=', AreasDict)
print('type(AreasDict)=', type(AreasDict))


...output:



    AreasDict= {'4G NeVe': 0, '4G FT ET': 400, '4G C-Plane': 800, 'MANO BTSSM': 0}
type(AreasDict)= <class 'dict'>


The column in the postgreSQL data base shows type 'jsonb':



enter image description here



This 'AreasDict' is used in the function of another project I want to call and re-use for my project. But in my project, I need to build up the data from another source. So I create a data frame and try to assign that 'AreasDict' ()...



    column_names = ['issue_key', jsonCol]
df = pd.DataFrame(index=range(1,2), columns=column_names)
df.iloc[0, 0] = exampleKey
df.iloc[0, 1] = AreasDict


... and with the last code line I get that error




ValueError: Incompatible indexer with Series




What do I do wrong?










share|improve this question




















  • 1





    Problem is in pandas is not recomended store dicts in DataFrame column, but one possible solution is use df.iloc[0, 1] = [AreasDict]

    – jezrael
    Nov 20 '18 at 9:04











  • Yes, that turns it into class 'list' !! I'll try that in my project that calls the function using it and let you know.

    – Joe Phi
    Nov 20 '18 at 9:09













  • So it working for you nice? It is what you need?

    – jezrael
    Nov 20 '18 at 9:10








  • 1





    I still have to try that principle in my 'real' project that calls the shared function and see if that function eats it.Will let you know.

    – Joe Phi
    Nov 20 '18 at 9:11






  • 1





    the workaround? this one: if isinstance(AreasDict, str) : then AreasDict = ast.literal_eval(AreasDict

    – Joe Phi
    Nov 20 '18 at 13:51














0












0








0








As a newbie to python I'm struggling with an error "Incompatible indexer with Series".



I'm reading a entry from a postgreSQL database:



    df_postgresDB = pd.read_sql_query('SELECT * FROM public.json_view',con=<...>)        
exampleKey = 'FPB-83160'
jsonCol = 'efforts'
AreasDict = df_postgresDB.loc[exampleKey, jsonCol]
print('AreasDict=', AreasDict)
print('type(AreasDict)=', type(AreasDict))


...output:



    AreasDict= {'4G NeVe': 0, '4G FT ET': 400, '4G C-Plane': 800, 'MANO BTSSM': 0}
type(AreasDict)= <class 'dict'>


The column in the postgreSQL data base shows type 'jsonb':



enter image description here



This 'AreasDict' is used in the function of another project I want to call and re-use for my project. But in my project, I need to build up the data from another source. So I create a data frame and try to assign that 'AreasDict' ()...



    column_names = ['issue_key', jsonCol]
df = pd.DataFrame(index=range(1,2), columns=column_names)
df.iloc[0, 0] = exampleKey
df.iloc[0, 1] = AreasDict


... and with the last code line I get that error




ValueError: Incompatible indexer with Series




What do I do wrong?










share|improve this question
















As a newbie to python I'm struggling with an error "Incompatible indexer with Series".



I'm reading a entry from a postgreSQL database:



    df_postgresDB = pd.read_sql_query('SELECT * FROM public.json_view',con=<...>)        
exampleKey = 'FPB-83160'
jsonCol = 'efforts'
AreasDict = df_postgresDB.loc[exampleKey, jsonCol]
print('AreasDict=', AreasDict)
print('type(AreasDict)=', type(AreasDict))


...output:



    AreasDict= {'4G NeVe': 0, '4G FT ET': 400, '4G C-Plane': 800, 'MANO BTSSM': 0}
type(AreasDict)= <class 'dict'>


The column in the postgreSQL data base shows type 'jsonb':



enter image description here



This 'AreasDict' is used in the function of another project I want to call and re-use for my project. But in my project, I need to build up the data from another source. So I create a data frame and try to assign that 'AreasDict' ()...



    column_names = ['issue_key', jsonCol]
df = pd.DataFrame(index=range(1,2), columns=column_names)
df.iloc[0, 0] = exampleKey
df.iloc[0, 1] = AreasDict


... and with the last code line I get that error




ValueError: Incompatible indexer with Series




What do I do wrong?







json pandas jsonb






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 20 '18 at 9:00







Joe Phi

















asked Nov 20 '18 at 8:49









Joe PhiJoe Phi

11011




11011








  • 1





    Problem is in pandas is not recomended store dicts in DataFrame column, but one possible solution is use df.iloc[0, 1] = [AreasDict]

    – jezrael
    Nov 20 '18 at 9:04











  • Yes, that turns it into class 'list' !! I'll try that in my project that calls the function using it and let you know.

    – Joe Phi
    Nov 20 '18 at 9:09













  • So it working for you nice? It is what you need?

    – jezrael
    Nov 20 '18 at 9:10








  • 1





    I still have to try that principle in my 'real' project that calls the shared function and see if that function eats it.Will let you know.

    – Joe Phi
    Nov 20 '18 at 9:11






  • 1





    the workaround? this one: if isinstance(AreasDict, str) : then AreasDict = ast.literal_eval(AreasDict

    – Joe Phi
    Nov 20 '18 at 13:51














  • 1





    Problem is in pandas is not recomended store dicts in DataFrame column, but one possible solution is use df.iloc[0, 1] = [AreasDict]

    – jezrael
    Nov 20 '18 at 9:04











  • Yes, that turns it into class 'list' !! I'll try that in my project that calls the function using it and let you know.

    – Joe Phi
    Nov 20 '18 at 9:09













  • So it working for you nice? It is what you need?

    – jezrael
    Nov 20 '18 at 9:10








  • 1





    I still have to try that principle in my 'real' project that calls the shared function and see if that function eats it.Will let you know.

    – Joe Phi
    Nov 20 '18 at 9:11






  • 1





    the workaround? this one: if isinstance(AreasDict, str) : then AreasDict = ast.literal_eval(AreasDict

    – Joe Phi
    Nov 20 '18 at 13:51








1




1





Problem is in pandas is not recomended store dicts in DataFrame column, but one possible solution is use df.iloc[0, 1] = [AreasDict]

– jezrael
Nov 20 '18 at 9:04





Problem is in pandas is not recomended store dicts in DataFrame column, but one possible solution is use df.iloc[0, 1] = [AreasDict]

– jezrael
Nov 20 '18 at 9:04













Yes, that turns it into class 'list' !! I'll try that in my project that calls the function using it and let you know.

– Joe Phi
Nov 20 '18 at 9:09







Yes, that turns it into class 'list' !! I'll try that in my project that calls the function using it and let you know.

– Joe Phi
Nov 20 '18 at 9:09















So it working for you nice? It is what you need?

– jezrael
Nov 20 '18 at 9:10







So it working for you nice? It is what you need?

– jezrael
Nov 20 '18 at 9:10






1




1





I still have to try that principle in my 'real' project that calls the shared function and see if that function eats it.Will let you know.

– Joe Phi
Nov 20 '18 at 9:11





I still have to try that principle in my 'real' project that calls the shared function and see if that function eats it.Will let you know.

– Joe Phi
Nov 20 '18 at 9:11




1




1





the workaround? this one: if isinstance(AreasDict, str) : then AreasDict = ast.literal_eval(AreasDict

– Joe Phi
Nov 20 '18 at 13:51





the workaround? this one: if isinstance(AreasDict, str) : then AreasDict = ast.literal_eval(AreasDict

– Joe Phi
Nov 20 '18 at 13:51












1 Answer
1






active

oldest

votes


















1














In pandas non scalar values are poorly supported - many function should failed.





Solution is convert to list for list of dictionary:



jsonCol = 'j'
exampleKey = 'key'
AreasDict= {'4G NeVe': 0, '4G FT ET': 400, '4G C-Plane': 800, 'MANO BTSSM': 0}

column_names = ['issue_key', jsonCol]
df = pd.DataFrame(index=range(1,2), columns=column_names)
df.iloc[0, 0] = exampleKey
df.iloc[0, 1] = [AreasDict]
print (df)
issue_key j
1 key [{'4G NeVe': 0, '4G FT ET': 400, '4G C-Plane':...





share|improve this answer























    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%2f53389252%2fpython-pandas-assigning-a-json-data-to-a-data-frame-entry-returns-error-incomp%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    In pandas non scalar values are poorly supported - many function should failed.





    Solution is convert to list for list of dictionary:



    jsonCol = 'j'
    exampleKey = 'key'
    AreasDict= {'4G NeVe': 0, '4G FT ET': 400, '4G C-Plane': 800, 'MANO BTSSM': 0}

    column_names = ['issue_key', jsonCol]
    df = pd.DataFrame(index=range(1,2), columns=column_names)
    df.iloc[0, 0] = exampleKey
    df.iloc[0, 1] = [AreasDict]
    print (df)
    issue_key j
    1 key [{'4G NeVe': 0, '4G FT ET': 400, '4G C-Plane':...





    share|improve this answer




























      1














      In pandas non scalar values are poorly supported - many function should failed.





      Solution is convert to list for list of dictionary:



      jsonCol = 'j'
      exampleKey = 'key'
      AreasDict= {'4G NeVe': 0, '4G FT ET': 400, '4G C-Plane': 800, 'MANO BTSSM': 0}

      column_names = ['issue_key', jsonCol]
      df = pd.DataFrame(index=range(1,2), columns=column_names)
      df.iloc[0, 0] = exampleKey
      df.iloc[0, 1] = [AreasDict]
      print (df)
      issue_key j
      1 key [{'4G NeVe': 0, '4G FT ET': 400, '4G C-Plane':...





      share|improve this answer


























        1












        1








        1







        In pandas non scalar values are poorly supported - many function should failed.





        Solution is convert to list for list of dictionary:



        jsonCol = 'j'
        exampleKey = 'key'
        AreasDict= {'4G NeVe': 0, '4G FT ET': 400, '4G C-Plane': 800, 'MANO BTSSM': 0}

        column_names = ['issue_key', jsonCol]
        df = pd.DataFrame(index=range(1,2), columns=column_names)
        df.iloc[0, 0] = exampleKey
        df.iloc[0, 1] = [AreasDict]
        print (df)
        issue_key j
        1 key [{'4G NeVe': 0, '4G FT ET': 400, '4G C-Plane':...





        share|improve this answer













        In pandas non scalar values are poorly supported - many function should failed.





        Solution is convert to list for list of dictionary:



        jsonCol = 'j'
        exampleKey = 'key'
        AreasDict= {'4G NeVe': 0, '4G FT ET': 400, '4G C-Plane': 800, 'MANO BTSSM': 0}

        column_names = ['issue_key', jsonCol]
        df = pd.DataFrame(index=range(1,2), columns=column_names)
        df.iloc[0, 0] = exampleKey
        df.iloc[0, 1] = [AreasDict]
        print (df)
        issue_key j
        1 key [{'4G NeVe': 0, '4G FT ET': 400, '4G C-Plane':...






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 20 '18 at 9:43









        jezraeljezrael

        326k23270346




        326k23270346






























            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%2f53389252%2fpython-pandas-assigning-a-json-data-to-a-data-frame-entry-returns-error-incomp%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

            Can a sorcerer learn a 5th-level spell early by creating spell slots using the Font of Magic feature?

            Does disintegrating a polymorphed enemy still kill it after the 2018 errata?

            A Topological Invariant for $pi_3(U(n))$