Hi,

the content of the CSV is stored as an array after reading. You can
simply access rows and columns like in Matlab:

firstrow = a1[0]
firstcol = a1.T[0]

The .T transposes the array.

The second element of the third row would be

elem32 = a1[2][1]
which is equivalent to
elem32 = a1[2,1]

A range of e.g. rows 3 to 6 is
range36 = a1[2:6]

Please have a look here for getting started with scipy/numpy:
http://pages.physics.cornell.edu/~myers/teaching/ComputationalMethods/python/arrays.html
and
http://www.scipy.org/NumPy_for_Matlab_Users

Hope this helps,
Daniel

2011/5/27 Karthikraja Velmurugan <velmurugan.karthikr...@gmail.com>:
> Hello Daniel,
>
> The code you have given is simple and works fab. Thank you very much. But I
> wasn't able to find an example which accesses the columns of a CSV files
> when I import data through "datafile="filename.csv"" option. It will be
> great if you could help with accessing individual columns. What excatly I am
> looking for is to access individual coulmns (of the same CSV file), do
> calculations using the two coumnsĀ and plot them into seperate subplots of
> the same graph.
> I modified the script a lil bit. Please find it below:
>
> import matplotlib.pyplot as plt
> import pylab
> datafile1 = 'ch1_s1_lrr.csv'
> datafile2 = 'ch1_s1_baf.csv'
> a1 = pylab.loadtxt(datafile1, comments='#', delimiter=';')
> b1 = pylab.loadtxt(datafile2, comments='#', delimiter=';')
> v1 = [0,98760,0,1]
> v2 = [0,98760,-2,2]
> plt.figure(1)
> plt.subplot(4,1,1)
> print 'loading', datafile1
> plt.axis(v2)
> plt.plot(a1, 'r.')
> plt.subplot(4,1,2)
> print 'loading', datafile2
> plt.axis(v1)
> plt.plot(b1, 'b.')
> plt.show()
>
> Thank you very much in advance for your time and suggestions.
>
> Karthik

------------------------------------------------------------------------------
vRanger cuts backup time in half-while increasing security.
With the market-leading solution for virtual backup and recovery, 
you get blazing-fast, flexible, and affordable data protection.
Download your free trial now. 
http://p.sf.net/sfu/quest-d2dcopy1
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to