I'm new to python and am trying to load data from a file. My file looks like this:
TION 13168375
NTHE 11234972
THER 10218035
THAT 8980536
OFTH 8132597
FTHE 8100836
THES 7717675
WITH 7627991
I want to extract both columns into separate arrays. What I tried so far is:
import numpy as np
s=open("Equadgrams.txt", "r")
data = np.genfromtxt(s, dtype=[('mystring','S4'),('myint','i8')])
In the documentation of the loadtxt command it looked like I can split the result into separate arrays, but this gave me errors.
x,y = np.loadtxt(s, dtype=[('mystring','S4'),('myint','i8')])
Traceback (most recent call last):
File "<input>", line 3, in <module>
ValueError: too many values to unpack (expected 2)
One additional thing that I noticed: The integers in the data array seem to be alright, but the strings are not read as intended. I get for the first entry: b'TION' which is of type class<class 'numpy.bytes_'>
I hope that someone is so kind to help me with my problem.