import pandas as pd
import matplotlib.pyplot as plt
读取数据,仅读取所需列
data = pd.read_csv(r"C:\Users\XXGC\Desktop\shiuxun3.csv", usecols=["订单编号", "总金额"])
计算订单数量
order_count = data["订单编号"].nunique()
计算总金额的总和
total_amount = data["总金额"].sum()
计算平均订单金额
average_amount = total_amount / order_count
打印整体购物情况
print("订单数量:", order_count)
print("总金额:", total_amount)
print("平均订单金额:", average_amount)
读取数据,仅读取所需列
data = pd.read_csv(r"C:\Users\XXGC\Desktop\shiuxun3.csv", usecols=["订单编号", "总金额", "买家实际支付金额"])
计算已付款订单的数量和总金额
paid_orders = data[data["买家实际支付金额"] > 0]
paid_order_count = paid_orders["订单编号"].nunique()
paid_total_amount = paid_orders["买家实际支付金额"].sum()
计算未付款订单的数量和总金额
unpaid_orders = data[data["买家实际支付金额"] == 0]
unpaid_order_count = unpaid_orders["订单编号"].nunique()
unpaid_total_amount = unpaid_orders["总金额"].sum()
打印总销售情况
print("已付款订单数量:", paid_order_count)
print("已付款订单总金额:", paid_total_amount)
print("未付款订单数量:", unpaid_order_count)
print("未付款订单总金额:", unpaid_total_amount)
读取数据,仅读取所需列
data = pd.read_csv(r"C:\Users\XXGC\Desktop\shiuxun3.csv", usecols=["订单编号", "总金额"])
计算产品价格的平均值、中位数、最大值和最小值
price_stats = data["总金额"].agg(["mean", "median", "max", "min"])
读取数据
data = pd.read_csv(r"C:\Users\XXGC\Desktop\shiuxun3.csv")
将订单创建时间转换为日期时间格式
data["订单创建时间"] = pd.to_datetime(data["订单创建时间"])
按小时对订单创建时间进行分组,并计算每个小时的订单数量和总金额
hourly_sales = data.groupby(data["订单创建时间"].dt.hour).agg({"订单编号": "nunique", "总金额": "sum"})
绘制折线图展示销售趋势
plt.figure(figsize=(10, 6))
plt.plot(hourly_sales.index, hourly_sales["订单编号"], label="订单数量")
plt.plot(hourly_sales.index, hourly_sales["总金额"], label="总金额")
plt.xlabel("小时")
plt.ylabel("数量/金额")
plt.title("销售趋势(按小时)")
plt.legend()
plt.grid(True)
plt.show()
打印产品价格分析
print(price_stats)