0

I've been having trouble calling csv files in form of tuples with python.

I'm using:

csv_data = np.genfromtxt('csv-data.csv', dtype=int, delimiter=',', names=True)

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

Trial1 Trial2 Trial3
50-------70----90
60-------70----80

(data of 3 trials by 2 people)

My genfromtxt() code from above would generate:

csv_data=[(50, 70, 90) (60, 70, 80)]

While I want to separate the data by person with a comma like:

csv_data = [(50, 70, 90), (60, 70, 80)]

Any help from here on?

martineau
  • 119,623
  • 25
  • 170
  • 301
Vinci
  • 365
  • 1
  • 6
  • 16

1 Answers1

1

I think you can use the tolist method.

http://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.html

It will convert the ndarray to a list.

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

The result of the above code is:

➜ /tmp/csv $ python3 test.py
[(50, 70, 90), (60, 70, 80)]
<class 'list'>
bwangel
  • 732
  • 1
  • 7
  • 12