Unsuccessful Importing .txt file containing 11 rows info and then real data starts

Viewed 83

I am trying to import so many text files (probably around 100) as you see in the pic. Basically, I tried to use read_csv to import them but it did not work. So, files are kinda in a little bit complex form. I need to separate them in a proper way. The real data (31 columns including time in the first column) that I am going to use starts at 12th row. However, I'd like to keep those first 11 rows as well such that i.e. I can match the Measurements labels with each column in the future. Lastly, I am gonna need to write a for loop to import 100 txt files and read every 31 columns and first 11 info rows in those. DATA VIEW I tried read.csv by doing a lot of things even including skiprows, however it did not work out.Then, I also implemented the following code but not perfectly it gave me what I wanted to have

one of the things I've tried is

with open('zzzAD1.TXT', 'r') as the_file:
    all_data = [line.split() for line in the_file.readlines()]
    height_line = all_data[:11]
    data = all_data[11:]

So, could anyone help me please?

1 Answers

If you're trying to get this into pandas, the only problem is that you need to convert the strings to floats, and you'll have to figure out what column headings to use, but you're basically on the right track here.

with open('zzzAD1.TXT', 'r') as the_file:
    all_data = [line.split() for line in the_file.readlines()]
    height_line = all_data[:11]
    data = all_data[11:]

data = [ [float(x) for x in row] for row in data]
df = pandas.DataFrame(data)
Related