Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jun 9th, 2012  |  syntax: None  |  size: 0.62 KB  |  hits: 35  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. How can I combine two fields into one when importing from a file into numpy array?
  2. #RIC,Date[G],Time[G],GMT Offset,Type,Open,High,Low,Last,Volume
  3. ADH0,20100103,22:18:00.000,-6,Intraday 1Min,0.8915,0.8915,0.8915,0.8915,0
  4. ADH0,20100103,22:22:00.000,-6,Intraday 1Min,0.89,0.89,0.89,0.89,0
  5.        
  6. a = np.genfromtxt(f, names=True, delimiter=',', dtype="|S8,i4,|S12,f8", usecols=(0, 1, 2, 8), autostrip=True)
  7.        
  8. gawk -F, '{print $1","$2"_"$3","$4","$5","$6","$7","$8","$9","$10}' input.csv
  9.        
  10. raw_csv = csv.reader(open('file'))
  11. joined_columns = np.array([[[i[0]]+[str(i[1])+'sep_string'+str(i[2])]+i[3:]]
  12.                  for i in raw_csv])