4

I was trying to add the individual rows of my array which I changed from a dataframe, and after adding all the rows, I was trying to save the array into a csv file and I get this error: Expected 1D or 2D array, got 0D array instead. My code where I believe the problem lies is below:

array = dfmain.values
shareArray = array[:1]
shareArray = dividedPV/shareArray
array = shareArray * array
sums = [sum(j) for j in array]
finalArray = np.array(sums, dtype=np.float16) #tried to change it from list to Array to see if that was the problem



#changes the file name to whatever the variables (portname etc) were given above
filename = "calculated_%s_%s_%s.csv" % (portName, inceptionDate, frequency)
np.savetxt("%s.csv", filename, finalArray, delimiter = ",")

Any tips would be greatly appreciated!

1
  • 2
    You're using "%s.csv" as the filename, then filename as the array, then finalArray as the format string. So, the problem is that filename is a 0D array (with a string dtype). You probably wanted "%s.csv' % (filename,) as one argument, rather than "%s.csv", filename as two separate arguments. Commented May 17, 2018 at 20:14

1 Answer 1

2

The first argument of np.savetxt is the filename; you have two filenames as arguments and the actual array to be saved as the third argument, it should be the second.

i.e.

np.savetxt(filename, finalArray, delimiter=',')
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.