Home > Net >  adding data into dataframe elementwise
adding data into dataframe elementwise

Time:01-01

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 [1x6] 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

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 [1x6] 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

CodePudding user response:

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

  • Related