You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
33 lines
1.0 KiB
33 lines
1.0 KiB
import csv
|
|
import matplotlib.pyplot as plt
|
|
plt.rcParams['font.sans-serif']=['Arial Unicode MS']#防止图片乱码
|
|
plt.rcParams['font.sans-serif'] = ['SimHei'] # 用来正常显示中文标签
|
|
plt.rcParams['axes.unicode_minus'] = False # 用来正常显示负号
|
|
|
|
brand=[]
|
|
price=[]
|
|
v=[]
|
|
m=[]
|
|
q=[]
|
|
with open('联想笔记本.csv','r',encoding='utf-8-sig') as file:#打开文件
|
|
reader=csv.reader(file)
|
|
for item in reader: #遍历文件内容放入列表中
|
|
v.append(item[2])
|
|
v=v[1:] #切片去头
|
|
with open('联想笔记本.csv','r',encoding='utf-8-sig') as file:#打开文件
|
|
reader=csv.reader(file)
|
|
for item in reader: #遍历文件内容放入列表中
|
|
m.append(item[0])
|
|
m=m[1:] #切片去头
|
|
for i in m: #从商品名称中提取商品品牌
|
|
q=i[0]+i[1]
|
|
brand.append(q)
|
|
for x in v:
|
|
price.append(float(x))
|
|
plt.style.use('ggplot')
|
|
plt.scatter(brand,price)
|
|
plt.xlabel('brand')
|
|
plt.ylabel('price')
|
|
plt.title('价格分析')
|
|
plt.show()
|