Search code examples
pythonpandasboxplotdata-analysis

Making box-plot with only particular rows pandas python


So, I have data looking like this. This is a very small set of how my dataset looks.

   VehicleID    FinancialYear   Type                Make    ConditionScore
        119        2000-01     Personnel Vehicle    Ford            55
        124        2000-01    Heavy Goods Vehicle   MAN             10
        174        2000-01    Light Goods Vehicle   Ford            20
        400        2002-03    Light Goods Vehicle   Volkswagen      65
        475        2002-03    Personnel Vehicle      Ford          100
        774        2003-03    Light Goods Vehicle    MAN            35
        845        2006-07     Personnel Vehicle     Ford           60
        847        2006-07    Heavy Goods Vehicle   Ford            50
        956        2006-07  Light Goods Vehicle Iveco               10

I am trying to create a boxplot of the particular years (so like, boxplot of just the values of 2000-01 and then just values of 2006-07) but since I'm a little new to pandas python struggling a bit. Could anyone suggest ways to do the above?


Solution

  • Something like this should work:

    import pandas as pd
    import matplotlib.pyplot as plt
    
    # Create small dummy data set, import your real data here instead
    data = pd.DataFrame([['2009-10', 89], ['2009-10', 60], ['2010-11', 85]],
                        columns=['Year', 'Score'])
    
    plt.figure()
    data[data['Year'] == '2009-10'].boxplot(column='Score')
    plt.savefig('plot.png')