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
- Command:
- python script.py
- Output:
- key 10.0 finished
- key 20.0 finished
- Output file:
- 1.000000000000000056e-01,4.000000000000000222e-01
- 2.000000000000000111e-01,5.000000000000000000e-01
- 2.999999999999999889e-01,5.999999999999999778e-01
Add Comment
Please, Sign In to add comment