Issue
I have a csv file with the following data stored as uncov_users.csv: 2867,2978
I am trying to get the data from the CSV file and print it but I am getting an error. I need the data in separate variables so I am using the for i,j
loop.
My Code:
import numpy as np
uncov_users = np.genfromtxt('ucov_users.csv', delimiter=',')
for i,j in uncov_users:
ux_coor = i
uy_coor = j
print(ux_coor,uy_coor)
Error:
Traceback (most recent call last):
File "D:\Programmes\Final_Year\Plot_DFO\test.py", line 3, in <module>
for i, j in uncov_users:
TypeError: cannot unpack non-iterable numpy.float64 object
I am just trying to understand what is wrong with it and how can it be fixed.
Solution
Try this:
import numpy as np
text = open("ucov_users.csv", "r")
text = ''.join([i for i in text]) \
.replace(" ", "\n")
x = open("ucov_users.csv", "w")
x.writelines(text)
x.close()
uncov_users = np.genfromtxt('ucov_users.csv', delimiter=',')
for i,j in uncov_users:
ux_coor = i
uy_coor = j
print(ux_coor,uy_coor)
Answered By - 3nws
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.