[Python] TypeError: concat() takes 1 positional argument but 2 were given

Discussão em 'Python' iniciado por Stack, Janeiro 27, 2025.

  1. Stack

    Stack Membro Participativo

    I want to concatenate the pandas dataframes in a column-wise manner and reset the index.

    import pandas as pd
    import numpy as np

    com_mut = kirc_mut.loc[common_samples]
    com_mut = com_mut.sort_index()
    com_mut = com_mut.T
    com_mut = com_mut.dropna()
    com_mut = com_mut.groupby(com_mut.index).first()

    com_mut = com_mut.T
    l=[com_mut[x].apply(pd.Series).stack() for x in com_mut.columns]
    common_mut=pd.concat(l,1).reset_index(level=1,drop=True)


    Traceback:

    ---------------------------------------------------------------------------
    TypeError Traceback (most recent call last)
    Input In [24], in <cell line: 9>()
    7 com_mut = com_mut.T
    8 l=[com_mut[x].apply(pd.Series).stack() for x in com_mut.columns]
    ----> 9 common_mut=pd.concat(l,1).reset_index(level=1,drop=True)
    10 common_mut.columns=com_mut.columns
    12 common_mut

    TypeError: concat() takes 1 positional argument but 2 were given


    Data:

    common_samples[1:10]

    Index(['TCGA-A3-3367-01', 'TCGA-A3-3387-01', 'TCGA-B0-4698-01',
    'TCGA-B0-4710-01', 'TCGA-B0-4810-01', 'TCGA-B0-4811-01',
    'TCGA-B0-4815-01', 'TCGA-B0-4818-01', 'TCGA-B0-4821-01'],
    dtype='object')


    kirc_mut.iloc[0:9,0:9]

    pd.DataFrame({'A1BG': {'TCGA-A3-3313-01': 0,
    'TCGA-A3-3313-01A.': 0,
    'TCGA-A3-3317-01': 1,
    'TCGA-A3-3319-01': 0,
    'TCGA-A3-3319-01A.': 0,
    'TCGA-A3-3320-01': 0,
    'TCGA-A3-3320-01A.': 0,
    'TCGA-A3-3331-01': 0,
    'TCGA-A3-3346-01': 0},
    'A1CF': {'TCGA-A3-3313-01': 0,
    'TCGA-A3-3313-01A.': 0,
    'TCGA-A3-3317-01': 0,
    'TCGA-A3-3319-01': 0,
    'TCGA-A3-3319-01A.': 0,
    'TCGA-A3-3320-01': 0,
    'TCGA-A3-3320-01A.': 0,
    'TCGA-A3-3331-01': 0,
    'TCGA-A3-3346-01': 0},
    'A2M': {'TCGA-A3-3313-01': 0,
    'TCGA-A3-3313-01A.': 1,
    'TCGA-A3-3317-01': 0,
    'TCGA-A3-3319-01': 0,
    'TCGA-A3-3319-01A.': 1,
    'TCGA-A3-3320-01': 0,
    'TCGA-A3-3320-01A.': 0,
    'TCGA-A3-3331-01': 0,
    'TCGA-A3-3346-01': 0},
    'A2ML1': {'TCGA-A3-3313-01': 0,
    'TCGA-A3-3313-01A.': 0,
    'TCGA-A3-3317-01': 0,
    'TCGA-A3-3319-01': 0,
    'TCGA-A3-3319-01A.': 0,
    'TCGA-A3-3320-01': 0,
    'TCGA-A3-3320-01A.': 0,
    'TCGA-A3-3331-01': 0,
    'TCGA-A3-3346-01': 0},
    'A4GNT': {'TCGA-A3-3313-01': 0,
    'TCGA-A3-3313-01A.': 0,
    'TCGA-A3-3317-01': 0,
    'TCGA-A3-3319-01': 0,
    'TCGA-A3-3319-01A.': 0,
    'TCGA-A3-3320-01': 1,
    'TCGA-A3-3320-01A.': 0,
    'TCGA-A3-3331-01': 0,
    'TCGA-A3-3346-01': 0},
    'AAAS': {'TCGA-A3-3313-01': 0,
    'TCGA-A3-3313-01A.': 1,
    'TCGA-A3-3317-01': 0,
    'TCGA-A3-3319-01': 0,
    'TCGA-A3-3319-01A.': 0,
    'TCGA-A3-3320-01': 0,
    'TCGA-A3-3320-01A.': 0,
    'TCGA-A3-3331-01': 0,
    'TCGA-A3-3346-01': 0},
    'AADAC': {'TCGA-A3-3313-01': 0,
    'TCGA-A3-3313-01A.': 0,
    'TCGA-A3-3317-01': 0,
    'TCGA-A3-3319-01': 0,
    'TCGA-A3-3319-01A.': 0,
    'TCGA-A3-3320-01': 0,
    'TCGA-A3-3320-01A.': 0,
    'TCGA-A3-3331-01': 0,
    'TCGA-A3-3346-01': 0},
    'AADACL3': {'TCGA-A3-3313-01': 0,
    'TCGA-A3-3313-01A.': 0,
    'TCGA-A3-3317-01': 0,
    'TCGA-A3-3319-01': 0,
    'TCGA-A3-3319-01A.': 0,
    'TCGA-A3-3320-01': 1,
    'TCGA-A3-3320-01A.': 0,
    'TCGA-A3-3331-01': 0,
    'TCGA-A3-3346-01': 0},
    'AADACL4': {'TCGA-A3-3313-01': 0,
    'TCGA-A3-3313-01A.': 0,
    'TCGA-A3-3317-01': 0,
    'TCGA-A3-3319-01': 0,
    'TCGA-A3-3319-01A.': 0,
    'TCGA-A3-3320-01': 1,
    'TCGA-A3-3320-01A.': 0,
    'TCGA-A3-3331-01': 0,
    'TCGA-A3-3346-01': 0}})

    Continue reading...

Compartilhe esta Página