Advertisement
Guest User

Untitled

a guest
Jun 15th, 2019
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.27 KB | None | 0 0
  1. arrays = [np.hstack([['One']*2, ['Two']*2]) , ['A', 'B', 'C', 'D']]
  2. columns = pd.MultiIndex.from_arrays(arrays)
  3. data = pd.DataFrame(np.random.randn(5, 4), columns=list('ABCD'))
  4. data.columns = columns
  5. import seaborn as sns
  6. cm = sns.light_palette("green", as_cmap=True)
  7. data.style.background_gradient(cmap=cm, subset=['A'])
  8.  
  9. data.style.background_gradient(cmap=cm, subset=pd.IndexSlice[:, pd.IndexSlice[:, 'A']])
  10.  
  11. In [5]: data.loc[pd.IndexSlice[:, pd.IndexSlice[:, 'A']]]
  12. Out[5]:
  13. One
  14. A
  15. 0 -0.808483
  16. 1 0.009371
  17. 2 0.977138
  18. 3 -0.875554
  19. 4 -0.052424
  20.  
  21. In [6]: data
  22. Out[6]:
  23. One Two
  24. A B C D
  25. 0 -0.808483 -2.280683 0.576145 0.649688
  26. 1 0.009371 0.721510 1.013764 -0.157493
  27. 2 0.977138 1.441392 1.718618 -0.320826
  28. 3 -0.875554 -1.060507 1.457075 0.570195
  29. 4 -0.052424 -0.742842 -0.203830 -1.202091
  30.  
  31. data.style.background_gradient(cmap=cm, subset=[('One','A')])
  32.  
  33. arrays = [np.hstack([['One']*2, ['Two']*2]) , ['A', 'B', 'C', 'D']]
  34. columns = pd.MultiIndex.from_arrays(arrays)
  35. data = pd.DataFrame(np.random.randn(5, 4), columns=list('ABCD'))
  36. data.columns = columns
  37. cm = sns.light_palette("green", as_cmap=True)
  38. data.style.background_gradient(cmap=cm, subset=[('One','A'),('Two','C')])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement