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:
- 10,0.1
- 10,0.2
- 10,0.3
- 20,0.4
- 20,0.5
- 20,0.6
- 30,0.3
- 10,0.9
- Command:
- python script.py
- Output:
- key 10.0 finished
- Traceback (most recent call last):
- File "script.py", line 13, in <module>
- result = np.vstack((result, col))
- File "/home/user/.local/lib/python2.7/site-packages/numpy/core/shape_base.py", line 234, in vstack
- return _nx.concatenate([atleast_2d(_m) for _m in tup], 0)
- ValueError: all the input array dimensions except for the concatenation axis must match exactly
Advertisement
Add Comment
Please, Sign In to add comment