pandas笔记-总结之一

本文通过数据分析,揭示了2002年至2018年上海机动车车牌拍卖的趋势,包括中标率低于5%的情况,各年度车牌最低价的最大值、平均值及四分位数,以及月度统计数据的变化。同时,探讨了相邻月份最低价和平均价的差值,并筛选出两者变化趋势相反的月份。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

在这里插入图片描述

import pandas as pd
import numpy as np
df=pd.read_csv('2002年-2018年上海机动车拍照拍卖.csv')
df.head()

在这里插入图片描述

df['ratio']=df['Total number of license issued']/df['Total number of applicants']
df[df['ratio']<0.05].head()

在这里插入图片描述

df.drop(columns='ratio',inplace=True)
df_3 = df.copy()
## 截取-
df_3['Year'] = df_3['Date'].apply(lambda x : 2000+int(x.split('-')[0]))
df_3['Month'] = df_3['Date'].apply(lambda x : x.split('-')[1])
newcolumns = ['Year','Month']+list(df.columns[0:5])
df_4 = df_3.reindex(columns=newcolumns).copy()
df_4.head()

在这里插入图片描述

## 按年分组
df_5 = df_4.groupby('Year')['lowest price '].agg([('Maximun','max'),('mean','mean'),('0.75Quantile',lambda x:x.quantile(0.75))])
df_5.head()

在这里插入图片描述

df_6 = df_4.copy()
## 先转化索引
df_6 = df_6.melt(id_vars=['Year', 'Month'],value_vars=['Total number of license issued', 'lowest price ', 'avg price', 'Total number of applicants'])
df_6 = pd.pivot_table(df_6,index=['Year', 'variable'],columns='Month',values='value').rename_axis(index={'variable':'统计项目'})
df_6.head(10)

在这里插入图片描述

df_7= df_4[['Year','Month','lowest price ','avg price']].copy()
## 怎么处理上个月 从已排序中下一行取
df_7=df_7.iloc[1:].reset_index()[['Month','lowest price ','avg price']].join(df_7,rsuffix='_lastmonth',how='outer')
df_7['lowest_diff'] = df_7['lowest price ']-df_7['lowest price _lastmonth']
df_7['avg_diff'] = df_7['avg price']-df_7['avg price_lastmonth']
df_7 = df_7[(df_7['lowest_diff']*df_7['avg_diff'])<0][['Year','Month']]
df_7

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值