How to call csv data into tuples in python with numpy genfromtxt?
<p>I've been having trouble calling csv files in form of tuples with python.</p>

<p>I'm using:  </p>

<pre><code>    csv_data = np.genfromtxt('csv-data.csv', dtype=int, delimiter=',', names=True)
</code></pre>

<p>While the data looks like: (sorry I don't know how to display csv format)</p>

<p>Trial1 Trial2 Trial3</p>

<p>50-------70----90 </p>

<p>60-------70----80</p>

<p>(data of 3 trials by 2 people)</p>

<p>My genfromtxt code from above would generate:</p>

<pre><code>csv_data=[(50, 70, 90) (60, 70, 80)]
</code></pre>

<p>while I want to separate the data by person with a comma like:</p>

<pre><code>csv_data=[(50, 70, 90), (60, 70, 80)]
</code></pre>

<p>Any help from here on?
Thank you!</p>

<p>I think you can use the <code>tolist</code> method.</p>

<p><a href="http://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.html" rel="nofollow">http://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.html</a></p>

<p>It will convert the ndarray to a list.</p>

<pre><code>import numpy as np
csv_data = np.genfromtxt('csv-data.csv', dtype=int, delimiter=',', names=True)
print(csv_data.tolist())
</code></pre>

<p>The result of the above code is:</p>

<pre><code>â /tmp/csv $ python3 test.py
[(50, 70, 90), (60, 70, 80)]
&lt;class 'list'&gt;
</code></pre>

python csv numpy genfromtxt