numpy - How to replace certain symbols in dtype.names in Python? -


i have data file of form given below:

column_1    column 2    column-3    column-4    column_5    column 6 1   2   3   1   2   3 4   3   2   3   2   4 1   4   3   1   4   3 5   6   4   5   6   4 

when import following file header names spaces automatically replaced underscores replace spaces. how preserve hyphens. code used is:

import numpy np open('data.dat', 'rb') f:     header = f.readline().split('\t')     arr = np.genfromtxt(f, names = header, comments='#', delimiter='\t', dtype=none) arr.dtype.names = [j.replace('_', ' ').replace('-', ' ') j in arr.dtype.names] print arr.dtype.names 

output

('column_1', 'column_2', 'column3', 'column4', 'column_5', 'column_6') 

how hyphens of column 3 , 4 in python?

hint - can use regex extracting data in columns, above case expression similar exp = r'column.\d'


Comments

Popular posts from this blog

javascript - gulp-nodemon - nodejs restart after file change - Error: listen EADDRINUSE events.js:85 -

Fatal Python error: Py_Initialize: unable to load the file system codec. ImportError: No module named 'encodings' -

javascript - oscilloscope of speaker input stops rendering after a few seconds -