Division between column values and rows using pandas

Asked

Viewed 1,838 times

1

I created a table pivot containing some values, but I do not know if it is necessary to use pivot table in this case below is a sample of the results:

             Valor ajuste                                          \
Data posicao   2017-05-30   2017-05-31   2017-06-01    2017-06-02   
Ativo                                                               
FUT AUD        -8478.0000  273771.0000   82449.0000  -177507.0000   
FUT BGI        75900.0000  -60720.0000   95634.0000    13662.0000   
FUT CAD        59314.5000  177849.0000  -40956.3000   -24179.4000   

I need to divide between these values and the following dataframe values:

          Data   Patrimonio
0   2017-05-30  50451168.08
1   2017-05-31  51057040.07
2   2017-06-01  51641619.65

On each date it is necessary to carry out a division of the Value adjusted by Patrimonio. What are the ways to do it?

OBS.: The result of the division will be used for another calculation after this.

1 answer

1


df_1 = pd.DataFrame(np.random.randint(0,28,size=(10, 4)), columns=list('ABCD'))
df_2 = pd.DataFrame(np.random.randint(0,28,size=(4, 1)), columns=list('A'))
df_3 = pd.DataFrame(np.zeros(( df_1.shape[0] , df_1.shape[1] )) , columns=list('ABCD'))

for data in range(len(df_1.columns)):
    df_3[ list(df_1.columns)[data] ] =  df_1[ list(df_1.columns)[data] ] / df_2.iloc[data]['A']
df_3

Browser other questions tagged

You are not signed in. Login or sign up in order to post.