-1

I'm starting to get familarized with Python and I wanted to learn how to read a txt files, like the ones that are obtained from other software, like LabView, which normally have the following structure.

Headline

Other information

Temperature 1 [Tab] Temperature 2 [Tab] Pressure

In other words, skip the first few lines, and get the data which is separated with Tab in columns and store it in a list.

CeliaL
  • 3
  • 1

1 Answers1

0

This could work for you. It reads the file and automatically detects tabs as delimiter, because it is set on whitespace per default. Other possibilities to set as delimiter are for example ';' or ',' etc.

Check: https://numpy.org/doc/stable/reference/generated/numpy.loadtxt.html

import numpy as np
np.loadtxt('data.txt',skiprows = 2)
Stefan
  • 897
  • 4
  • 13
  • Oh, nice, didn't know that function. I've observed that the values stored are float and doesn't seem to be possible to convert them to integers by putting int(). Also, and thank you for your kind answer, is there a simple way to extract the values of the, for example, first column? – CeliaL Dec 14 '20 at 00:19
  • Good to hear that you managed to implement the function. If it was what you were looking for then please accept the answer with the tick symbol next to my answer. :) – Stefan Dec 14 '20 at 08:56