furas

pandas - type, min, max

Apr 23rd, 2017
326
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.55 KB | None | 0 0
  1. import pandas as pd
  2.  
  3. df = pd.DataFrame({
  4.         'numbers': list(range(10)),
  5.         'chars': list('abcdefghij'),
  6.         'floats': [0.1*x for x in range(10)],
  7.      })
  8.  
  9. header = 'numbers'
  10. print('header:', header)
  11. print('type:', df[header].dtypes)
  12. print('min,max:', df[header].min(), df[header].max())
  13. print('-------------------------------')
  14.  
  15. header = 'chars'
  16. print('header:', header)
  17. print('type:', df[header].dtypes)
  18. print('min,max:', df[header].min(), df[header].max())
  19. print('-------------------------------')
  20.  
  21. headers = ['numbers', 'floats']
  22. print('headers:', headers)
  23. print('--- type ---')
  24. print(df[headers].dtypes)
  25. print('--- min ---')
  26. print(df[headers].min())
  27. print('--- max ---')
  28. print(df[headers].max())
  29. print('-------------------------------')
  30.  
  31. print('--- type ---')
  32. print(df.dtypes['numbers'])
  33. print(df.dtypes['floats'])
  34. print('--- min ---')
  35. print(df.min()['numbers'])
  36. print(df.min()['floats'])
  37. print('--- max ---')
  38. print(df.max()['numbers'])
  39. print(df.max()['floats'])
  40. print('-------------------------------')
  41.  
  42. '''
  43. header: numbers
  44. type: int64
  45. min,max: 0 9
  46. -------------------------------
  47. header: chars
  48. type: object
  49. min,max: a j
  50. -------------------------------
  51. headers: ['numbers', 'floats']
  52. --- type ---
  53. numbers      int64
  54. floats     float64
  55. dtype: object
  56. --- min ---
  57. numbers    0.0
  58. floats     0.0
  59. dtype: float64
  60. --- max ---
  61. numbers    9.0
  62. floats     0.9
  63. dtype: float64
  64. -------------------------------
  65. --- type ---
  66. int64
  67. float64
  68. --- min ---
  69. 0
  70. 0.0
  71. --- max ---
  72. 9
  73. 0.9
  74. -------------------------------
  75. '''
Advertisement
Add Comment
Please, Sign In to add comment