酒类消费数据统计

该代码段展示了使用Pandas库对CSV文件中的饮品消费数据进行处理,包括导入数据、计算各大陆啤酒平均消耗量、显示每个大陆红酒的描述性统计信息、列出所有酒类的平均消耗以及spirit饮品的平均、最大和最小消耗值。

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

1:导入数据

import pandas as pd
date_path=pd.read_csv('./drinks.csv')
pd.set_option('display.max_row',200)
print(date_path.info())
print(date_path.head())

2:哪个大陆平均消耗的啤酒最多?

import pandas as pd
date_path=pd.read_csv('./drinks.csv')
pd.set_option('display.max_row',200)
# print(date_path.info())
# print(date_path.head())
beer_mean=date_path.groupby('continent').mean().beer_servings
print(beer_mean)

#列索引要加iloc,而行索引用切片,切片只是加[:1]

3:打印出每个大陆(continent)的红酒消耗(wine_servings)的描述性统计信息

#使用describe的信息

import pandas as pd
date_path=pd.read_csv('./drinks.csv')
pd.set_option('display.max_row',200)
print(date_path.groupby('continent').wine_servings.describe())


4:打印出每个大陆每种酒类别的消耗平均值

import pandas as pd
date_path=pd.read_csv('./drinks.csv')
pd.set_option('display.max_row',200)
print(date_path.groupby('continent').mean())

5:打印出每个大陆对spirit饮品消耗的平均值,最大值,最小值(.agg聚合的意思,是aggregate的意思)

import pandas as pd
date_path=pd.read_csv('./drinks.csv')
pd.set_option('display.max_row',200)
print(date_path.groupby('continent').spirit_servings.agg(['mean','max','min']))

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值