0

I have 3 pandas dataframes as :

abc
xyz
colour
type
pattern
colour
type
pattern
lenght
breadth
height
area
lenght
breadth
height
area

I want to combine the dataframes so that it looks like this :

abc colour   length
    type     breadth
    pattern  height
             area 
xyz colour   length
    type     breadth
    pattern  height
             area

I also want to export the end result to an excel sheet so how do i do that without making it look messy?

sahil
  • 15
  • 4
  • What do you want the dataframes to merge on? Here is a good [post](https://stackoverflow.com/questions/53645882/pandas-merging-101) explaining how to merge the dataframes. Then you will have to perform a `groupby` operation over each sub column type. Also, please add more details (like data samples, what you have tried till now) and specify where exactly you need help – Anurag Reddy Oct 13 '20 at 19:25

1 Answers1

0

first concat second and third df with rows of first df and concat them:

df1 = pd.DataFrame([['abc'],['xyz']],columns=['col1'])
df2 = pd.DataFrame([['colour'],
['type'],
['pattern']],columns=['col2'])

df3 = pd.DataFrame([['lenght'],
['breadth'],
['height'],
['area']],columns=['col3'])

pd.concat([pd.concat([df[lambda x: x.index == i].reset_index(),df2,df3],axis=1) for i in range(len(df1))]).drop('index',axis=1)
Mehdi Golzadeh
  • 2,594
  • 1
  • 16
  • 28