Pandas Task6 综合测试

这篇博客通过三个案例展示了Pandas在数据分析中的应用:分析2002-2018年上海机动车车牌拍卖数据,包括中标率、时间列拆分、统计分析等;2007-2019年俄罗斯机场货运航班运载量,涉及年度总运量、机场分布、货运排名等;以及新冠肺炎在美国的传播,计算相关系数、零感染县比例、最早确诊县等关键指标。
摘要由CSDN通过智能技术生成

一、2002 年-2018 年上海机动车拍照拍卖

问题
(1) 哪一次拍卖的中标率首次小于 5%?

load_path = '../data/'
df_car = pd.read_csv(load_path+'2002年-2018年上海机动车拍照拍卖.csv')
df_car
df_car['rate'] = df_car['Total number of license issued'] / df_car['Total number of applicants']
df_car.loc[df_car['rate']<0.05].head()

在这里插入图片描述

15年的5月

(2) 将第一列时间列拆分成两个列,一列为年份(格式为 20××),另一列为
月份(英语缩写),添加到列表作为第一第二列,并将原表第一列删除,
其他列依次向后顺延。

list_date = list(df_car['Date'].str.split('-'))
list_year = [x[0] for x in list_date]
list_month = [x[1] for x in list_date]

df_car['month'] = list_month

def year_change(x):
    y = []
    for i in x:
        if len(i) == 1:
            y.append('200'+i)
        else:
            y.append('20'+i)
    return y

list_year1 = year_change(list_year)  
df_car['year'] = list_year1
df_car.drop(columns='Date', inplace=True)

cols = list(df_car.columns)
cols.remove('month')
cols.remove('year')
cols.insert(0, 'month')
cols.insert(0, 'year')
cols
df_car = df_car[cols]
df_car

在这里插入图片描述

(3) 按年统计拍卖最低价的下列统计量:最大值、均值、0.75 分位数,要求
显示在同一张表上。

df_car.groupby('year')['lowest price '].agg(['max', 'mean', ('quantile(q=0.75)' ,lambda x: x.quantile(q=0.75))])

在这里插入图片描述

(4) 现在将表格行索引设为多级索引,外层为年份,内层为原表格第二至第
五列的变量名,列索引为月份。

df_car.set_index(['year', 'Total number of license issued', 'lowest price ', 'avg price', 'Total number of applicants'])

在这里插入图片描述

(5) 一般而言某个月最低价与上月最低价的差额,会与该月均值与上月均值
的差额具有相同的正负号,哪些拍卖时间不具有这个特点?

list_1 = []
list_2 = []
for i in range(202):
    list_1.append(df_car.loc[i+1, 'lowest price '] - df_car.loc[i, 'lowest price '])
    list_2.append(df_car.loc[i+1, 'avg price'] - df_car.loc[i, 'avg price'])
    
def pos_neg(list1, list2):
    index = []
    for i in range(202):
        if list1[i] * list2[i] < 0:
            index.append(i+1)
    
    return index
    
df_car.loc[index_list]

在这里插入图片描述

(6) 将某一个月牌照发行量与其前两个月发行量均值的差额定义为发行增
益,最初的两个月用 0 填充,求发行增益极值出现的时间。

list_issue = []
for i in range(201):
    list_issue.append
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值