I have a T 2D dataframe as Follow :
dfB = pd.DataFrame([[cheapest_brandB[0],wertBereichB]], columns=['brand', 'price'], index=
['cheap'])
dfC = pd.DataFrame([[cheapest_brandC[0],wertBereichC]], columns=['brand', 'price'], index=
['cheap'])
the Result :
brand price
cheap ASUS 200
brand price
cheap HP 500
How can I merge the 2d and turn it into a 3d dataframe, where every 2d columns are under the name of Gaming or casual.
i want somthing like that :
Gaming Casual
brand price brand price
cheap ASUS 200 HP 500
Can anyone help me?
Use concat with keys parameter:
df = pd.concat([dfB, dfC], axis=1, keys=('Gaming','Casual'))
print (df)
Gaming Casual
brand price brand price
cheap ASUS 200 HP 500
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With