Reputation: 1397
My sample code will be like this
import numpy as np
from io import BytesIO
data = "1, 2, 3\n4, 5, 6"
np.genfromtxt(data, delimiter=",")
while run this code throws error
Traceback (most recent call last): File "", line 1, in TypeError: a bytes-like object is required, not 'str'
Upvotes: 1
Views: 563
Reputation: 1105
Encode the string before reading it:
data = "1, 2, 3\n4, 5, 6"
np.genfromtxt(BytesIO(data.encode()), delimiter=",")
array([[ 1., 2., 3.],
[ 4., 5., 6.]])
Upvotes: 2