使用pandas进行基础的图表的绘制

利用pandas进行图表的基础的绘制,以下是根据课程学习的代码部分。供自己日后学习备查。

import pandas
import matplotlib.pyplot as plt

books = pandas.read_excel("./15天父商品流量.xlsx",index_col="序列")

books["订单商品数量转化率"] = books["已订购商品数量"]/books["买家访问次数"]

books.to_excel("./15天父商品流量.xlsx")
books = books.loc[books["age"].apply(lambda a: 18<=a<26)].loc[books.score.apply(lambda b: 80<=b<100)]

books = pandas.read_excel("./cauclate.xlsx",index_col="id")
books["total"] = books.oct + books.nov + books.nov
books.sort_values(by='total',inplace=True)
books.plot.bar(x="field",y="num",color = "red",title="machine language percent")
books.plot.barh(x="field",y=["oct","nov","dec"],stacked = True)
plt.xlabel("field",fontsize = 16, fontweight = "bold")
plt.ylabel("num",fontsize = 16, fontweight = "bold")
ax = plt.gca()
ax.set_xticklabel(books.field,rotation = 45,ha = "right")

# 画饼图
books["2020"].plot.pie(startangle = -270)

# 画折线图
books.plot.area(y=["accessories","bikes","clothing","components"])
plt.xticks(books.index,fontsize = 8)

# 画散点图
books.plot.scatter(y = "sqft_living",x = "price")

# 画直方图
books.sqft_living.plot.hist(bins=100)
plt.xticks(range(0,max(books.sqft_living),500))  # x轴以序列显示

# 画密度图
books.sqft_living.plot.kde()

plt.title("machine language percent",fontweight = "bold")
plt.tight_layout()
plt.show()

print(books.corr())
books.to_excel("./cauclate.xlsx")
上一篇:专业3 原生数据分页


下一篇:Redis(1)——5种基本数据结构