I have two attributes age (float) and name (string) that belongs to a person. I want to write them to csv file, hence, I used numpy to store data, then write it to csv.
import numpy as np
import random
age_name = np.empty((2, 10))
print (age_name.shape)
for i in range (10):
age = random.randint(0,100)
name = 'ABC'
age_name[0,i]=age
age_name[1,i]=name
print (age_name)
I got the error
Traceback (most recent call last): File "python", line 9, in ValueError: could not convert string to float: 'ABC'
It may be a not a good option because the data has both string and float number, could you suggest to me a good way that can easy to store to csv file?
dtype = objecttonp.emptyor use a custom data-type if efficiency matters.age_name = np.empty((2, 10), dtype=str)and print (age_name) will be[['8' '2' '6' '4' '9' '9' '7' '6' '2' '4'] ['A' 'A' 'A' 'A' 'A' 'A' 'A' 'A' 'A' 'A']]