-1

I have data I want to plot and analyse, looking like:

0101 
1  3
2  4
3  6

I use skip_header in genfromtxt to load the file 2 column data, however I also need the header for reference.

Is there a way to get the header back?

hpaulj
  • 221,503
  • 14
  • 230
  • 353
StarStrides
  • 121
  • 3
  • 10
  • Use a regular Python file read to get that line, – hpaulj Nov 19 '18 at 10:11
  • For `genfrontxt` this isn't a valid column header. So are right to skip it. And there's no provision for saving or recording skipped lines. Why should there be? – hpaulj Nov 19 '18 at 16:18

2 Answers2

0

I am not sure that this is implemented in numpy.genfromtxt(). You may have to call the function twice, once for the header, and a second time for the data. Or you may want to have a look at the functions offered by pandas, such as read_table.

Patol75
  • 4,342
  • 1
  • 17
  • 28
0

You can try with pd.read_csv:

data = pd.read_csv(filename, sep=" ")

So that the first line is read as header

Joe
  • 12,057
  • 5
  • 39
  • 55