Dumping numpy array into an excel file

前端 未结 2 1201
感动是毒
感动是毒 2021-01-04 20:56

I am trying to dump numpy array into an excel file using savetxt method, but I am getting this weird error on the console:

.18e,%.18e,%.18e,%.18e,%.18e,%.18e         


        
相关标签:
2条回答
  • 2021-01-04 21:46

    you could use pandas, its really easy friendly to use.

    import pandas as pd
    
    ## convert your array into a dataframe
    df = pd.DataFrame (array)
    
    ## save to xlsx file
    
    filepath = 'my_excel_file.xlsx'
    
    df.to_excel(filepath, index=False)
    

    hope it helps!

    0 讨论(0)
  • 2021-01-04 21:48

    Bit late, but might help others facing such an issue.

    This error is because you appear to have set

    dtype = np.ndarray

    when creating / defining your Numpy matrix first_layer_output.

    One solution to this problem is modifying your command storing the

    np.savetxt('test.csv', first_layer_output, delimiter=',', fmt='%s')
    

    This command now outputs the contents of the array as a string, irrespective the actual data types being used. Hope this helps.

    0 讨论(0)
提交回复
热议问题