python - numpy.genfromtxt: Ambiguous delimiters? -


i'm trying write generic script, part of imports files either comma-separated or white-space-separated. i'd script recognize either type. there way specify like

arrayobj = np.genfromtxt(file.txt, delimiter=(',' or '\t'), names=none, dtype=none) 

i tried using regular expression (',|\t') doesn't work either.

as mentioned not believe there way np.genfromtxt; can use python pandas.

example.txt: 1,2,3 #header 1,2,3 4,5'tab'6 7'tab'8'tab'9 

using pandas read_csv:

print pd.read_csv('example.csv',sep='\t|,').values [[1 2 3]  [4 5 6]  [7 8 9]] 

Comments

Popular posts from this blog

How to mention the localhost in android -

php - Calling a template part from a post -

c# - String.format() DateTime With Arabic culture -