-2

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:

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

enter image description here

  • (1) Please post your code (and your data, in this case) as _text_, not images. (2) Your code doesn't show anything Pandas-related. – AKX Feb 09 '23 at 17:27

1 Answers1

1
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.

AKX
  • 152,115
  • 15
  • 115
  • 172