Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

separate a .txt file into two columns using pandas

I have a .txt file, without header. I am going to separate into two column with header X and Y that is ordered like this:

enter image description here

I have read text file into pandas:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

How can I have data frame with two column and header X and Y?

enter image description here

>Solution :

df = pd.read_csv(
  "reference.txt",
  delim_whitespace=True,  # any whitespace separates data
  names=["x", "y"],  # column names
  index_col=False,  # no index
)

ought to do the trick.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading