一、2002 年-2018 年上海机动车拍照拍卖
Date | Total number of license issued | lowest price | avg price | Total number of applicants |
---|---|---|---|---|
日期 | 颁发许可证总数 | 最低价格 | 平均价格 | 申请人总数 |
2-Jan | 1400 | 13600 | 14735 | 3718 |
2-Feb | 1800 | 13100 | 14057 | 4590 |
2-Mar | 2000 | 14300 | 14662 | 5190 |
问题
(1) 哪一次拍卖的中标率首次小于 5%?
idf1 = df[df['Total number of license issued'] / df['Total number of applicants'] < 0.05]
print(idf1.index[0])
结果:
159
(2) 按年统计拍卖最低价的下列统计量:最大值、均值、0.75 分位数,要求
显示在同一张表上。(先进行(3))
group_year = idf2.drop(columns = ['Month',
'Total number of license issued','avg price',
'Total number of applicants']).groupby('Year')
idf3 = pd.DataFrame()
idf3['max'] = group_year['lowest price '].max()
idf3['mean'] = group_year['lowest price '].mean()
idf3['quantile'] = group_year['lowest price '].quantile(0.75)
print(idf3)
结果:
max | mean | quantile | |
---|---|---|---|
Year | |||
2002 | 30800 | 20316.666667 | 24300.0 |
2003 | 38500 | 31983.333333 | 36300.0 |
2004 | 44200 | 29408.333333 | 38400.0 |
2005 | 37900 | 31908.333333 | 35600.0 |
2006 | 39900 | 37058.333333 | 39525.0 |
2007 | 53800 | 45691.666667 | 48950.0 |
2008 | 37300 | 29945.454545 | 34150.0 |
2009 | 36900 | 31333.333333 | 34150.0 |
2010 | 44900 | 38008.333333 | 41825.0 |
2011 | 53800 | 47958.333333 | 51000.0 |
2012 | 68900 | 61108.333333 | 65325.0 |
2013 | 90800 | 79125.000000 | 82550.0 |
2014 | 74600 | 73816.666667 | 74000.0 |
2015 | 85300 | 80575.000000 | 83450.0 |
2016 | 88600 | 85733.333333 | 87475.0 |
2017 | 93500 | 90616.666667 | 92350.0 |
2018 | 89000 | 87825.000000 | 88150.0 |
(3) 将第一列时间列拆分成两个列,一列为年份(格式为 20××),另一列为
月份(英语缩写),添加到列表作为第一第二列,并将原表第一列删除,
其他列依次向后顺延。
df['Year'] = df['Date'].apply(lambda x:2000 + int(x.split('-')[0]))
df['Month'] = df['Date'].apply(lambda x: x.split('-')[1])
idf2 = df.drop(columns = 'Date')
idf2 = idf2.reindex(columns = ['Year', 'Month',
'Total number of license issued', 'lowest price ',
'avg price', 'Total number of applicants'])
print(idf2.head())
结果:
Year | Month | … | avg price | Total | number of applicants | |
---|---|---|---|---|---|---|
0 | 2002 | Jan | … | 14735 | 3718 | |
1 | 2002 | Feb | … | 14057 | 4590 | |
2 | 2002 | Mar | … | 14662 | 5190 | |
3 | 2002 | Apr | … | 16334 | 4806 | |
4 | 2002 | May | … | 18357 | 4665 |
(4) 现在将表格行索引设为多级索引,外层为年份,内层为原表格第二至第
五列的变量名,列索引为月份。
我大概知道是什么形式,但我没弄出来
(5) 一般而言某个月最低价与上月最低价的差额,会与该月均值与上月均值
的差额具有相同的正负号,哪些拍卖时间不具有这个特点?
for index in range(202):
flag = (df.loc[index,'lowest price ']-df.loc