Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

adding data into dataframe elementwise

Appending array into excel columns elementwise

I am trying to automate my excel console sheet using python/pandas and numpy. I have already read the excel, converted data into arrays, did the matrix ops. and now I am getting row vector of [1×6] which I want to append into 6 columns. How to do this in pandas as I am very new in python!

import numpy as np
import openpyxl
s= pd.read_excel('ECOMP TRACKING.xlsx',sheet_name='SCHEDULE') #imprt as dataset
S = s.to_numpy() #converts to ndarray
veh = np.array(S[:,0])[np.newaxis] #gives 1xn matrix
V_sch=(S[:,1:])
e= pd.read_excel('ECOMP TRACKING.xlsx',sheet_name='EBOM')
E= e.to_numpy()
veh1 = np.array(E[:,2])[np.newaxis]  #gives 1xn matrix
#BO=B_0.T
b_1= veh1.size
i=0
while i<b_1:
    if veh1[0][i]==veh[0][0]:
        P1_sch=pd.ExcelWriter np.multiply(V_sch[0][:],E[i][5]*E[i][6])

        i+=1
    elif veh1[0][i]==veh[0][1]:
        P2_sch= np.multiply(V_sch[1][:],E[i][5]*E[i][6])
        i+=1
    elif veh1[0][i]==veh[0][2]:
        P3_sch= np.multiply(V_sch[2][:],E[i][5]*E[i][6])
        i+=1
    elif veh1[0][i]==veh[0][3]:
        P4_sch= np.multiply(V_sch[3][:],E[i][5]*E[i][6])
        i+=1
    elif veh1[0][i]==veh[0][4]:
        P5_sch= np.multiply(V_sch[4][:],E[i][5]*E[i][6])
        i+=1
    elif veh1[0][i]==veh[0][5]:
        P6_sch= np.multiply(V_sch[5][:],E[i][5]*E[i][6])
        i+=1
    else:
        i+=1```

I want to store each instance of P1_sch, P2_sch,.... into cells

Appending array into excel columns elementwise

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

I am trying to automate my excel console sheet using python/pandas and numpy. I have already read the excel, converted data into arrays, did the matrix ops. and now I am getting row vector of [1×6] which I want to append into 6 columns. How to do this in pandas as I am very new in python!

import numpy as np
import openpyxl
s= pd.read_excel('ECOMP TRACKING.xlsx',sheet_name='SCHEDULE') #imprt as dataset
S = s.to_numpy() #converts to ndarray
veh = np.array(S[:,0])[np.newaxis] #gives 1xn matrix
V_sch=(S[:,1:])
e= pd.read_excel('ECOMP TRACKING.xlsx',sheet_name='EBOM')
E= e.to_numpy()
veh1 = np.array(E[:,2])[np.newaxis]  #gives 1xn matrix
#BO=B_0.T
b_1= veh1.size
i=0
while i<b_1:
    if veh1[0][i]==veh[0][0]:
        P1_sch=pd.ExcelWriter np.multiply(V_sch[0][:],E[i][5]*E[i][6])

        i+=1
    elif veh1[0][i]==veh[0][1]:
        P2_sch= np.multiply(V_sch[1][:],E[i][5]*E[i][6])
        i+=1
    elif veh1[0][i]==veh[0][2]:
        P3_sch= np.multiply(V_sch[2][:],E[i][5]*E[i][6])
        i+=1
    elif veh1[0][i]==veh[0][3]:
        P4_sch= np.multiply(V_sch[3][:],E[i][5]*E[i][6])
        i+=1
    elif veh1[0][i]==veh[0][4]:
        P5_sch= np.multiply(V_sch[4][:],E[i][5]*E[i][6])
        i+=1
    elif veh1[0][i]==veh[0][5]:
        P6_sch= np.multiply(V_sch[5][:],E[i][5]*E[i][6])
        i+=1
    else:
        i+=1```

I want to store each instance of P1_sch, P2_sch,.... into cells

>Solution :

For your first vector, i.e. names of your columns, you might want to write:

df.columns = arr

For all the others:

df.append(arr)

https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.append.html

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading