Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Python script:
- import numpy as np
- data = np.genfromtxt('inputcsv', delimiter=',')
- keys = sorted(set(data[:,0]))
- result = np.array([])
- for k in keys:
- col = data[np.where(data[:,0] == k)][:,1]
- if not result.any():
- result = col
- else:
- result = np.vstack((result, col))
- print('key {0} finished'.format(k))
- np.savetxt('final.csv', np.transpose(result), delimiter=',')
- Input file:
- Column A | Column B
- 10 | 0.1
- 10 | 0.2
- 10 | 0.3
- 20 | 0.4
- 20 | 0.5
- 20 | 0.6
- Command:
- python script.py
- Output:
- Traceback (most recent call last):
- File "script.py", line 4, in <module>
- keys = sorted(set(data[:,0]))
- IndexError: too many indices for array
Add Comment
Please, Sign In to add comment