'Excel to text file Mismatch between array dtype ('<U12') and format specifier ('%.18e')

Currently I am:

  1. extracting colums from an Excel sheet
  2. Saving them as a matrix

I would like to save the new matrix in a text file

    import pandas as pd
    import os, sys
    import pandas as pd
    import numpy as np
    from openpyxl import load_workbook
    # Reading an excel file using Python 
    import xlrd 
    
    #or if your file is tab delimited '\t':
    df = pd.read_csv('batchTest2.txt', sep='\t')
    
    #To save to excel file add the following:
    df.to_excel('output.xlsx', 'Sheet1')
    
    # Give the location of the file 
    loc = ("outputUPDATED.xlsx") 
    wb = xlrd.open_workbook(loc) 
    sheet = wb.sheet_by_index(0)   
    
    #extract and save file
    for i in range(sheet.nrows): 
    matrix= [sheet.cell_value(i, 29),sheet.cell_value(i, 30),sheet.cell_value(i, 31),sheet.cell_value(i, 32),sheet.cell_value(i, 33),sheet.cell_value(i, 34),sheet.cell_value(i, 35),sheet.cell_value(i, 36),sheet.cell_value(i, 37),sheet.cell_value(i, 38),sheet.cell_value(i, 39),sheet.cell_value(i, 41),sheet.cell_value(i, 42),sheet.cell_value(i, 43),sheet.cell_value(i, 44),sheet.cell_value(i, 45),sheet.cell_value(i, 46),sheet.cell_value(i, 50)]
    data=np.array(matrix)
    with open("ModifiedBatch.txt", "w") as abc:
        np.savetxt(abc, data, delimiter=",")

But I get an error:

% (str(X.dtype), format))

TypeError: Mismatch between array dtype ('<U12') and format specifier ('%.18e')

I really tried to understand and look up different solutions, but I am still new at this. Right now I am thinking it has something to do with the format, but don't know what and how to fix it.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source