-3

here is my attempted code though it may be rubbish and to the right is the data, i just want the two columns of data from line 15 onwards

my code reads:

import numpy as np 
import matplotlib as mplt 

data = np.genfromtxt('practice_data.txt', 
                     dtype='float', 
                     delimiter='  ') 
time = data[:,0]
channel=data[:,1]  

if anyone can help me to extract the two columns as two variables that would be amazing

ateta96
  • 1
  • 1
  • Use the `usecols` parameter. Check the docs for exact name and usage – hpaulj Apr 17 '16 at 15:22
  • @ateta96 It will be polite to comment answer and say if your problem is solved with the solution or not .. – Essex Apr 18 '16 at 11:37
  • sorry! i haven't come back on the site in the last two days because i moved back to university. Thank you very much!, it is now working, though i also used some of the code in the answer below. – ateta96 Apr 18 '16 at 18:36

1 Answers1

0

With genfromtxt, you have a parameter which is named : skip_header. You can also extract the two columns as to variables like this :

data = np.genfromtxt('pratice_data.txt', 
                    dtype=[('first column name','f8'),('second column name','i8')], 
                    delimiter=' ', 
                    skip_header = 14)

skip_header = 14 let to pass the fourtheenth first lines.

I think that with this way, you can passed header and you get two columns that you can call after ;)

I didn't try the script, but it should work !

Good luck ;)

Essex
  • 6,042
  • 11
  • 67
  • 139
  • Thank you so much, that's got it working, really appreciate the help!! – ateta96 Apr 18 '16 at 18:37
  • sorry i thought id got it working but it says the 'size of tuple must match number of fields'. Im not too sure what that means.the code is the one put up by astrolabe1993, which made a lot of sense. If you have any thoughts that would be great – ateta96 Apr 18 '16 at 18:51