home
search
help
profile
liking the experience? our app is even better
registration for
employee referral programs
are now open
get referred to google, amazon, flipkart and more
register now  
showing results for pandas pivot table for many columns
1import pandas as pd
2import numpy as np
3arrays = [['Monday','Monday','Tursday','Tursday'],
4                        ['Morning','Noon','Morning','Evening']]
5tuples = list(zip(*arrays))
6index = pd.MultiIndex.from_tuples(tuples, names=['Weekday', 'Time'])
7df = pd.DataFrame(np.random.randint(5, size=(4,2)), index=index)
8
9In [39]: df
10Out[39]: 
11                 0  1
12Weekday Time         
13Monday  Morning  1  3
14        Noon     2  1
15Tursday Morning  3  3
16        Evening  1  2
17
18In [40]: pd.DataFrame(df.to_records())
19Out[40]: 
20   Weekday     Time  0  1
210   Monday  Morning  1  3
221   Monday     Noon  2  1
232  Tursday  Morning  3  3
243  Tursday  Evening  1  2
25
upvote
downvote
source