4

The main columns headers will be Dates like 22-June, 23-June, 24-June. Each of these dates will have two sub columns Named "High" and "Low". Now there will be high value and low value in High column and Low column for each Date column. Please advice

1 Answer 1

3

You can use from_product when creating a MultiIndex.

dates = ['2016-1-1', '2016-1-2', '2016-1-3']
cols = pd.MultiIndex.from_product([dates, ['High', 'Low']])

>>> pd.DataFrame(np.random.randn(1,6), columns=cols)
   2016-1-1            2016-1-2            2016-1-3          
       High       Low      High       Low      High       Low
0 -0.075206  0.464617  0.347055 -0.807486  0.871124 -0.375196
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks a ton. It was a great help as I am new to pandas and was not aware of MultiIndex feature
What About I want a custom date for each case? I cant do product

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.