My .txt file reads into my notebook as one column as opposed to three separate columns

Viewed 26

I used the following code which worked, but I had to erase the headers in the original .txt file in order for this to work.

por_layer5 =  pd.read_csv("Sample_File.txt",comment='#', header=None, delim_whitespace=True)

I wanted to know if there is a way to read in the .txt file and set conditions that only read in the integers and separate them into three columns without having to edit the original .txt file. I provided a preview of the first lines from the file that include the headers. My original thought was to index into the file to read-only when the numbers start (its index number is 4), but I've had trouble doing so.

Sample of the first couple of lines

1 Answers

You can use skiprows option in pd.read_csv.

pd.read_csv("Sample_File.txt",comment='#', header=None, skiprows=4,delim_whitespace=True)
Related