I want to pass csv data as argument in postman.
Which can be like
s = 2,3,4,5
s= "2,3,4,5"
This csv data is coming from some csv file. I can directly pas it like
localhost?data="2,3,4,5"
How to parse it correctly and convert it into numpy array?
I tried this
s = "2,3,4,5"
print(np.array(list(s)))
Which gives
['1' ',' '2' ',' '3' ',' '4']
which is wrong.
d =np.fromstring(s[1:-1],sep=' ').astype(int)
Gives array([], dtype=int64)
which I dont understand.
What is the correct way?
You can split on comma and then use np.array
Ex:
import numpy as np
s = "2,3,4,5"
print(np.array(s.strip('"').split(",")).astype(int))
Output:
[2 3 4 5]
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments