[Python] Pandas - only select rows containing a substring in a column

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

  1. Stack

    Stack Membro Participativo

    I have a file with many rows that look like this:

    012121 *************************************************** 3317 129862


    I'm using the following to select only the 'a' and 'c' columns:

    df = pd.read_csv('input.txt', sep='\\s+', error_bad_lines=False,warn_bad_lines=True,
    names=['a','b','c','d'])


    My problem is that there are headers and other unwanted information that I don't need or want to deal with, all throughout the file. What is the best way to only select those rows that contain '******' in column 'b' for my dataframe?

    Continue reading...

Compartilhe esta Página