对餐饮数据进行处理基于Python

对餐饮数据进行处理基于Python

餐饮网页数据源

#coding:utf-8

# 导入必要的模块

import pandas as pd
import numpy as np
import re
# 读取网页数据源

df = pd.read_csv(url,delimiter='\t')

print(df)
# 将餐名统一格式化
change_n = lambda x : str(re.sub('[^a-zA-Z0-9]',' ',x))

df.item_name = df.item_name.apply(change_n)
print(df.item_name)
# 将餐饮价格由str转化float类型
change_p = lambda x : float(x[1:])

df.item_price = df.item_price.apply(change_p)
# 统计每种套餐的销售数量

df = pd.pivot_table(df,values=['quantity'],index=['item_name'],aggfunc=np.sum)

print(df)
# 统计每种套餐的平均价钱

df = pd.pivot_table(df,values=['item_price'],index=['item_name'],aggfunc=np.mean)
print(df)

猜你喜欢

转载自blog.csdn.net/Forter_J/article/details/84951315