1. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

[Python] Pandas None acting as Text inconsistently across PCs

Discussão em 'Python' iniciado por Stack, Outubro 23, 2024 às 22:22.

  1. Stack

    Stack Membro Participativo

    I have a python script which works fine. We have a new user who when they run the same script get different results in how it handles the keyword None.

    The sample code is below and simply merges 2 data frames, but the issue is on how it applies the suffixes.

    import pandas as pd

    data = {
    'Name': ['Tom', 'nick', 'krish', 'jack'],
    'Age': [20, 21, 19, 18],
    'Parent': [1, 2, 3, 4]}

    data2 = {
    'Name': ['Tom', 'nick', 'krish', 'jack'],
    'Sex': ['M', 'M', 'M', 'F'],
    'Parent': [5, 6, 7, 8]}

    df = pd.DataFrame(data)
    df2 = pd.DataFrame(data2)
    df.info()
    df2.info()

    df3 = df.merge(df2, how='left', left_on='Name', right_on='Name', suffixes=[None,'_j'])
    df3.info()


    The expected and correct output of df3.info() is:

    # Column Non-Null Count Dtype
    --- ------ -------------- -----
    0 Name 4 non-null object
    1 Age 4 non-null int64
    2 Parent 4 non-null int64
    3 Sex 4 non-null object
    4 Parent_j 4 non-null int64


    However on the new user, they are getting per below. As you can see, column 2 is 'ParentNone' not 'Parent'. For some reason it is treating the suffix of None as the text 'None'.

    # Column Non-Null Count Dtype
    --- ------ -------------- -----
    0 Name 4 non-null object
    1 Age 4 non-null int64
    2 ParentNone 4 non-null int64
    3 Sex 4 non-null object
    4 Parent_j 4 non-null int64


    We are both running the same install of python. My pandas install is 1.4.4 but theirs is 1.4.2 but looking at GitHub for the merge function, there is no difference between the 2 versions of pandas.

    Any ideas on what on earth could be making one install treat None as text?

    Continue reading...

Compartilhe esta Página