viking_unet

Pandas example calculate statistics metrics

Jul 14th, 2020
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.50 KB | None | 0 0
  1. import pandas
  2.  
  3. df = pandas.read_csv('Life_expectancy_at_birth_male_years.csv', skiprows=4, index_col=[0,1,2,3])
  4. df.fillna(0,inplace=True)
  5. df.drop(df.columns[len(df.columns)-1], axis=1, inplace=True)
  6.  
  7. modes   = []
  8. medians = []
  9. stds    = []
  10. for buf_index, buf_value in df.iterrows():
  11.     modes.append(buf_value.mean())
  12.     medians.append(buf_value.median())
  13.     stds.append(buf_value.std())
  14.  
  15. df['mode']   = modes
  16. df['median'] = medians
  17. df['std']    = stds
  18.  
  19. df.to_csv('out.csv')
  20.  
  21. print('done')
Add Comment
Please, Sign In to add comment