Advertisement
furas

Python - example

May 21st, 2017
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.78 KB | None | 0 0
  1. import pandas as pd
  2.  
  3. data = [
  4.     [40, 60, 3, 3],
  5.     [60, 80, 8, 11],
  6.     [80, 100, 30, 41]
  7. ]
  8.  
  9. df = pd.DataFrame(data)
  10.  
  11. df['average'] = df[ [0,1] ].mean(axis=1)
  12. df['result'] = df[2] * df['average']
  13.  
  14. print(df)
  15.  
  16. '''
  17.     0    1   2   3  average  result
  18. 0  40   60   3   3     50.0   150.0
  19. 1  60   80   8  11     70.0   560.0
  20. 2  80  100  30  41     90.0  2700.0
  21. '''
  22. # ----------------------------------------------
  23.  
  24. data = [
  25.     [40, 60, 3, 3],
  26.     [60, 80, 8, 11],
  27.     [80, 100, 30, 41]
  28. ]
  29.  
  30. for row in data:
  31.     #d = [row[column] for column in [0,1]]
  32.     d = row[0:2]
  33.     average = sum(d)/len(d)
  34.     print(row, d, average, row[2]*average)
  35.  
  36. '''
  37. [40, 60, 3, 3] [40, 60] 50.0 150.0
  38. [60, 80, 8, 11] [60, 80] 70.0 560.0
  39. [80, 100, 30, 41] [80, 100] 90.0 2700.0
  40. '''
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement