[Python] Load a csv with consecutive trailing separators as separate null columns in a pandas...

Discussão em 'Python' iniciado por Stack, Março 14, 2025.

  1. Stack

    Stack Membro Participativo

    I have a csv file of the following format: 12;0;5/15/2008;1:01:09;1;0;0;None;97;39;0.279;;;0;;;;;0;0;0;;;;;;;;;;;;;;;;

    Then I read the file into a pandas dataframe:

    df = pd.read_csv(config.get("OS", "output_file"), header=None, delimiter=config.get("OS", "delimiter"), decimal=".")
    df=df.fillna(value='')
    print(df)


    and in the output I only have 13 columns ending with the last non-null column.

    How can I preserve the number of columns in the dataframe and have the trailing columns in the dataframe set to null?

    Continue reading...

Compartilhe esta Página