Home > Blockchain >  union of two pandas object with different dimensions
union of two pandas object with different dimensions

Time:06-07

I would like to combine two pandas dataframes with different dimensions first pandas date frame = df_a second pandas date frame = df_b

df_a :

  parametr   value
  a           value_1
  b           value_1
  c           value_3    

df_b - time sensor data :

  iter_0 t_1_1 t_1_2 t_1_3 t_1_4 t_1_5 t_1_6 t_1_7 t_1_8 t_1_9 t_1_10
  iter_1 t_2_1 t_2_2 t_2_3 t_2_4 t_2_5 t_2_6 t_2_7 t_2_8 t_2_9 t_2_10
  ...
  iter_n t_n_1 t_n_2 t_n_3 t_n_4 t_n_5 t_n_6 t_n_7 t_n_8 t_n_9 t_n_10

could you tell me how to make a union of different-sized pandas dataframe ?

CodePudding user response:

I would like the panadas dataframe obtained by concatenation df_a and df_b was like that df_ab :

  parametr   value
  a         value_1
  b         value_1
  c         value_3 
  iter_0 t_1_1 t_1_2 t_1_3 t_1_4 t_1_5 t_1_6 t_1_7 t_1_8 t_1_9 t_1_10
  iter_1 t_2_1 t_2_2 t_2_3 t_2_4 t_2_5 t_2_6 t_2_7 t_2_8 t_2_9 t_2_10
  ...
  iter_n t_n_1 t_n_2 t_n_3 t_n_4 t_n_5 t_n_6 t_n_7 t_n_8 t_n_9 t_n_10 

CodePudding user response:

i did so :

  f=pd.concat([test,tcalc_new],axis=0,sort=False,join="outer")

but the column names in df_b are on the same level as the column names in df_a , unfortunately I don't like it that way .

CodePudding user response:

I would like it to be like this:

  parametr   value
  a         value_1
  b         value_1
  c         value_3 
  iteration calc_1 calc_2 calc_3 calc_4 calc_5 calc_6 calc_7 calc_8 calc_9 calc_10 
  iter_0    t_1_1  t_1_2  t_1_3  t_1_4  t_1_5  t_1_6  t_1_7  t_1_8  t_1_9  t_1_10
  iter_1    t_2_1  t_2_2  t_2_3  t_2_4  t_2_5  t_2_6  t_2_7  t_2_8  t_2_9  t_2_10
  ...
  iter_n    t_n_1  t_n_2  t_n_3  t_n_4  t_n_5  t_n_6  t_n_7  t_n_8  t_n_9  t_n_10

where

  iteration calc_1 calc_2 calc_3 calc_4 calc_5 calc_6 calc_7 calc_8 calc_9 calc_10

is column names in df_b

  • Related