0

Hi I'm trying to save different numpy arrays to csv files using the following command in a looped script

df = pd.DataFrame(arr) - it fails here

df.astype(str).to_excel(outputFile)

It works fine for an array of the following shape and dtype

of (8L,) & [('add','

however when I try it with an array with the following shape and dtype

of (13L, 4L) & [('add', '

I get the following message

*** ValueError: If using all scalar values, you must pass an index

Any help would be gratefully received.

So the shape of the first csv file id 2 columns by 8 rows and ideally I'd like the 2nd csv to have a format of 8 columns by 13 rows

FN

funnyname
  • 31
  • 1
  • 3
  • See if this helps: https://stackoverflow.com/questions/17839973/constructing-pandas-dataframe-from-values-in-variables-gives-valueerror-if-usi – Anshul May 22 '20 at 11:12
  • When I try the following df = pd.DataFrame(arr, index=[0]) the message I get is *** Exception: Data must be 1-dimensional – funnyname May 22 '20 at 14:49
  • Can you share sample input and expected output in a copy pastable format? – Anshul May 22 '20 at 15:50
  • Thanks, how can I attach files? – funnyname May 22 '20 at 19:01
  • Please check this documentation once: https://stackoverflow.com/help/how-to-ask – Anshul May 22 '20 at 19:04
  • Also, one quick example could be a question like this: https://stackoverflow.com/questions/61928103/how-to-drop-by-selecting-rows-in-pandas/61928178#61928178 – Anshul May 22 '20 at 19:04
  • apologies and thanks for bearing with me but I'm just after noticing that some text isn't coming up in the main question. this is the shape and the dtype of the numpy array I am trying to save to csv - (13L, 4L) & [('add', ' – funnyname May 22 '20 at 19:18
  • This is the shape and dtype of the file that works when I save it to csv - (8L,) & [('add',' – funnyname May 22 '20 at 19:20

0 Answers0