0

I want to save a numpy array into a CSV file. My code gives me an error:

import os
import pandas as pd
import numpy as np

path ='/Users/mas/Documents/workspace/Avito/input/'                          # path to 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 is the error that I 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

1 Answer 1

3

You have to specify the form of data that you are going to save .By default it takes float as format

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

See section on savetxt function of SciPy documentation.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.