Guest User

Untitled

a guest
Aug 9th, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.50 KB | None | 0 0
  1. print ("""
  2. Name ID Email
  3. --------------------------------------------------""")
  4.  
  5.  
  6. data = [["Suresh Datta", 57394, "suresh@example.com"], ["Colette Browning", 48539, "colette@example.com"], ["Skye Homsi", 58302, "skye@example.com"], ["Hiroto Yamaguchi", 48502, "hiroto@example.com"], ["Tobias Ledford", 48291, "tobias@example.com"], ["Tamara Babic", 58201, "tamara@example.com"], ["Jin Xu", 48293, "jin@example.com"], ["Joana Dias", 23945, "joana@example.com"], ["Alton Derosa", 85823, "alton@example.com"]]
  7.  
  8. for row in data:
  9. for col in row:
  10. print ("%s t %f t %s" % (col, col,col, col,col, col,col, col,col, col,col, col,col, col,col, col,col, col,col, col,col, col,col, col))
  11.  
  12. print("""
  13. Name ID Email
  14. --------------------------------------------------""")
  15.  
  16. for row in data:
  17. print("{} t {} t {}".format(*row))
  18.  
  19. # pip install tabulate
  20. from tabulate import tabulate
  21. print(tabulate(data, headers=['Name', 'ID', 'Email'], tablefmt="grid"))
  22.  
  23. +------------------+-------+---------------------+
  24. | Name | ID | Email |
  25. +==================+=======+=====================+
  26. | Suresh Datta | 57394 | suresh@example.com |
  27. +------------------+-------+---------------------+
  28. | Colette Browning | 48539 | colette@example.com |
  29. +------------------+-------+---------------------+
  30. | Skye Homsi | 58302 | skye@example.com |
  31. +------------------+-------+---------------------+
  32. | Hiroto Yamaguchi | 48502 | hiroto@example.com |
  33. +------------------+-------+---------------------+
  34. | Tobias Ledford | 48291 | tobias@example.com |
  35. +------------------+-------+---------------------+
  36. | Tamara Babic | 58201 | tamara@example.com |
  37. +------------------+-------+---------------------+
  38. | Jin Xu | 48293 | jin@example.com |
  39. +------------------+-------+---------------------+
  40. | Joana Dias | 23945 | joana@example.com |
  41. +------------------+-------+---------------------+
  42. | Alton Derosa | 85823 | alton@example.com |
  43. +------------------+-------+---------------------+
  44.  
  45. import pandas as pd # pip install pandas
  46.  
  47. df = pd.DataFrame(data, columns=['Name','ID','Email'])
  48.  
  49. print(df)
  50.  
  51. Name ID Email
  52. 0 Suresh Datta 57394 suresh@example.com
  53. 1 Colette Browning 48539 colette@example.com
  54. 2 Skye Homsi 58302 skye@example.com
  55. 3 Hiroto Yamaguchi 48502 hiroto@example.com
  56. 4 Tobias Ledford 48291 tobias@example.com
  57. 5 Tamara Babic 58201 tamara@example.com
  58. 6 Jin Xu 48293 jin@example.com
  59. 7 Joana Dias 23945 joana@example.com
  60. 8 Alton Derosa 85823 alton@example.com
  61.  
  62. In [73]: print(df[df['Name'].str.contains(r'(?:Tamara|Joana)')].sort_values('ID'))
  63. Name ID Email
  64. 7 Joana Dias 23945 joana@example.com
  65. 5 Tamara Babic 58201 tamara@example.com
  66.  
  67. In [89]: for row in data:
  68. ...: print("{:>20} {:>10} {:>30}".format(*row))
  69. ...:
  70. ...:
  71. Suresh Datta 57394 suresh@example.com
  72. Colette Browning 48539 colette@example.com
  73. Skye Homsi 58302 skye@example.com
  74. Hiroto Yamaguchi 48502 hiroto@example.com
  75. Tobias Ledford 48291 tobias@example.com
  76. Tamara Babic 58201 tamara@example.com
  77. Jin Xu 48293 jin@example.com
  78. Joana Dias 23945 joana@example.com
  79. Alton Derosa 85823 alton@example.com
Add Comment
Please, Sign In to add comment