How to find the median and standard deviation by job in the below data in python?
Question: I have CSV file like below and i want to calculate the median and standard
deviation of salaries by each job

salaries.csv

    
    
    City   Job      Salary    
    Delhi  Doctors  500  
    Delhi  Lawyers  400  
    Delhi  Plumbers 100  
    London Doctors  800  
    London Lawyers  700  
    London Plumbers 300  
    Tokyo  Doctors  900  
    Tokyo  Lawyers  800  
    Tokyo  Plumbers 400  
    

From the above data i want to calculate the median and standard deviation of
salaries by each job

Expected Output 1:

    
    
    JOB      salary_median
    Doctors  400
    Lawyers  700
    plumbers 300
    

Expected output 2: JOB salary_std_dev Doctors 500 Lawyers 600 plumbers 400


Answer: This is a perfect task for pandas:

    
    
    import pandas as pd
    
    df = pd.DataFrame([
                       ['Delhi',  'Doctors',  500],
                       ['Delhi',  'Lawyers',  400],
                       ['Delhi',  'Plumbers', 100],
                       ['London', 'Doctors',  800],
                       ['London', 'Lawyers',  700],
                       ['London', 'Plumbers', 300],
                       ['Tokyo',  'Doctors',  900],
                       ['Tokyo',  'Lawyers',  800],
                       ['Tokyo',  'Plumbers', 400]],
                      columns = ['City',   'Job',      'Salary'])
    
    print df.groupby('Job').Salary.median().to_frame('salary_median')
    

