仅使用特定行制作箱线图 pandas python
Making box-plot with only particular rows pandas python
所以,我有这样的数据。这是我的数据集外观的一小部分。
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
我正在尝试创建特定年份的箱线图(例如,仅包含 2000-01 值的箱线图,然后仅包含 2006-07 年的值),但由于我对 [=18 有点陌生=] python 挣扎了一下。谁能建议执行上述操作的方法?
像这样的东西应该可以工作:
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')
所以,我有这样的数据。这是我的数据集外观的一小部分。
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
我正在尝试创建特定年份的箱线图(例如,仅包含 2000-01 值的箱线图,然后仅包含 2006-07 年的值),但由于我对 [=18 有点陌生=] python 挣扎了一下。谁能建议执行上述操作的方法?
像这样的东西应该可以工作:
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')