_property _DataFrame.T

返回转置。

  1. import pandas as pd
  2. df = pd.DataFrame({'site':['google', 'baidu', 'wiki', 'pandas'],
  3. 'age':[18, 39, 22, 45],
  4. 'price': [1.0, 2.0, 3.0, 4.0],
  5. 'color': ['red', 'black', 'blue', 'red']}, index=['first', 'second', 'third', 'forth'])
  6. df.T
  7. ---------------------------------------转置之前
  8. site age price color
  9. first google 18 1.0 red
  10. second baidu 39 2.0 black
  11. third wiki 22 3.0 blue
  12. forth pandas 45 4.0 red
  13. ---------------------------------------转置之后
  14. first second third forth
  15. site google baidu wiki pandas
  16. age 18 39 22 45
  17. price 1 2 3 4
  18. color red black blue red