I have a data file, which I need to read. I know to read files in Python you have to do something like:
file = open(fileLocaion, 'r+')
But I do not know who to do special reads. The data I have is in columns. So x values in one column and y values in another with headers at the top. The data (my text file a.txt) looks like
Charge (1x), Ch A, Run #1
Time ( s ) Charge (1x) ( µC )
0.0000 0.021
0.1000 0.021
0.2000 0.021
0.3000 0.021
0.4000 0.021
0.5000 0.021
0.6000 0.021
So the first time value is 0.0000 and the first charge value is 0.021. I want to be able to take this into Python and use matplotlib to plot it. But I am having trouble figuring out how to read this data.
If you’re going to be plotting it with matplotlib, probably the simplest thing to do is to use
numpy.loadtxt[docs], because you’ll have numpy installed anyway:Note that I had to add
skiprows=2here to skip the header. Then the times ared[:,0]and the chargesd[:,1], or you could get them explicitly withloadtxt: