python - error when writing numpy into csv file -


i want save numpy array csv file. code gives me error:

import os import pandas pd import numpy np  path ='/users/mas/documents/workspace/avito/input/'                          # path testing file  sample = pd.read_csv(path + 'samplesubmission.csv')  index = sample.id.values - 1  test =  np.array(pd.read_csv(path + 'dataset5test.csv'))  #print new[0:10,:]  new = test[index,:]  np.savetxt(path + 'testsearchstream9.csv', new, delimiter=",")  os.system('say "done"') 

this error get:

    np.savetxt(path + 'testsearchstream9.csv', new, delimiter=",")   file "/system/library/frameworks/python.framework/versions/2.7/extras/lib/python/numpy/lib/npyio.py", line 1061, in savetxt     fh.write(asbytes(format % tuple(row) + newline)) typeerror: float argument required, not str 

you have specify form of data going save .by default takes float format

np.savetxt(path + 'testsearchstream9.csv', new, delimiter=",", fmt="%s") 

see section on savetxt function of scipy documentation.


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

jquery - javascript onscroll fade same class but with different div -