1

I am trying to convert an excel sheet to a csv file, then converting that to a numpy array. However, when I use Data = df.to_numpy() it exports the first column as string variables, not float, while other values are perfectly converted. I don't know where the problems is coming from. Here is a sample of the output of Data[0]:

>>Data[0]
array(['0.01', 0.0, 0.01, 0.0, 0.01, 0.0, 0.01, 0.0, 0.01, 0.0, 0.01, 0.0,
       0.01, 0.0, 0.01, 0.0, 0.01, 0.0, 0.01, 0.0], dtype=object)

Here is the head of the data sheet in my excel sheet: enter image description here

and this is my code:

filename = "C:/Users/IMET/Desktop/One/MCC-200.xlsx"
Col_Names=[
            "Size (um)-3 bar","Volume (%)-PreRC", 
            "Size (um)-0.5 bar","Volume (%)-PreRC",
            "Size (um)-3 bar","Volume (%)-457um-3500rpm",
            "Size (um)-0.5 bar","Volume (%)-457um-3500rpm",
            "Size (um)-3 bar","Volume (%)-610um-3500rpm",
            "Size (um)-0.5 bar","Volume (%)-610um-3500rpm",
            "Size (um)-3 bar","Volume (%)-813um-3500rpm",
            "Size (um)-0.5 bar","Volume (%)-813um-3500rpm",
            "Size (um)-3 bar","Volume (%)-991um-3500rpm",
            "Size (um)-0.5 bar","Volume (%)-991um-3500rpm"
           ]


df = pd.read_excel(filename,'PSDs').to_csv('MyCSV.csv',index=False)

df2 = pd.read_csv('MyCSV.csv',skiprows = 4)

df2.dropna(axis=1,inplace=True,how='all')
df2.dropna(axis=0,inplace=True,how='any')

df2.columns=Col_Names

Data = df2.to_numpy()
user3015729
  • 191
  • 2
  • 7

0 Answers0