python练习——探索 Chipotle 快餐数据 

这篇博客通过Python对Chipotle快餐数据进行分析,包括加载数据到数据框、查看数据前10行、列数量与名称、最畅销商品、商品种类、商品下单总数、价格转换、总收入、订单数量及平均订单金额等。
部署运行你感兴趣的模型镜像

1. 将数据集存入一个名为 chipo 的数据框内 

import pandas as pd
chipo = pd.read_csv('chipotle.tsv',sep='\t')

知识点:

读取csv文件data=pd.read_csv('a.csv')
读取txt文件data = pd.read_table('a.txt')
读取json文件

data=pd.read_json('a.json')

 

读取excel文件

data=pd.read_excel('a.xsl')

data=pd.read_excel('a.xslx')


2. 查看前 10 行内容 
 

chipo.head(10)


3. 数据集中有多少个列(columns)?

chipo.columns.size
或者
chipo.shape[1]


4. 打印出全部的列名称 

chipo.columns
或者
chipo.keys()


5. 数据集的索引是怎样的? 

chipo.index


6. 被下单数最多商品(item)是什么? 

chipo["item_name"].value_counts().head(1)#下单数最多的商品是Chicken Bowl


7. 在 item_name 这一列中,一共有多少种商品被下单? 

len(chipo["item_name"].unique())#
或者
chipo["item_name"].nunique()

知识点:

8. 一共有多少个商品被下单? 

chipo["quantity"].sum()


9. 将 item_price 转换为浮点数 

print("转换前的数据类型",chipo["item_price"].dtypes)
for i in range(len(chipo["item_price"])):
    chipo["item_price"][i]=chipo["item_price"][i].replace('$','')
chipo["item_price"]=chipo["item_price"].astype('float')
print("转换后的数据类型",chipo["item_price"].dtypes)


10. 在该数据集对应的时期内,收入(revenue)是多少? 

chipo['sub_total'] = round(chipo['item_price'] * chipo['quantity'],2)#单价x数量
chipo['sub_total'].sum()

知识点:

round函数用于指定保留小数位数,返回四舍五入的结果


11. 在该数据集对应的时期内,一共有多少订单? 

len(chipo["order_id"].unique())
或者
chipo["order_id"].nunique()


12. 每一单(order)对应的平均总价是多少

(chipo['quantity']*chipo['item_price']).sum()/chipo["order_id"].nunique()

您可能感兴趣的与本文相关的镜像

Kotaemon

Kotaemon

AI应用

Kotaemon 是由Cinnamon 开发的开源项目,是一个RAG UI页面,主要面向DocQA的终端用户和构建自己RAG pipeline

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值