Skip to content Skip to sidebar Skip to footer

Take More Than One Value To Make A Table With Python Pandas

With my code I can join two Excel databases in 1. The problem is that it only shows me the Revenue column and not the column impressions. To be more clear I leave the code and the

Solution 1:

You can use:

  • join together both df
  • reshape for column with categories Impresiones and Revenue
  • sorting index, second level descendent
  • change first level of index by mask and set to index

df = (pd.concat([df1,df2])
        .set_index(["Cliente",'Fecha'])
        .stack()
        .unstack(1)
        .sort_index(ascending=(True, False)))

m = df.index.get_level_values(1) == 'Impresiones'
df.index = np.where(m, 'Impresiones', df.index.get_level_values(0))
print (df)
Fecha       20/12/17 21/12/17
Esteban         $150     $899
Impresiones    12345     2345
Jose            $667     $989
Impresiones     654n    12345
Martin           $20      $10
Impresiones     3245     3245
Mauro            $50      $98
Impresiones     2345      654
Pedro          $3000     $879
Impresiones      645      645

Post a Comment for "Take More Than One Value To Make A Table With Python Pandas"