新手的python笔记

xlrd库

import xlrd
(先在cmd里pip install xlrd
然后在pycharm里 找到file里的setting的
在这里插入图片描述
点击
在这里插入图片描述
这里我们需要导入xlrd,pyecharts,xlutils,
导入不成功需要检测是否下载成功,这里的pyecharts下载0.5.6版本
如果下载失败再安装Anaconda.
导入库

import xlrd
# from xlutils.copy import copy
from pyecharts import Bar
from pyecharts import Pie
# 要打开的表单名称
path ="housing.xls"
# 打开表单的方法
book =xlrd.open_workbook(path)
# 获取excel李的表单的名称有两种方法,随便用哪种都可以
# sheet=book.sheet_by_name("housing")
sheet=book.sheet_by_index(0)
# 查看具体某一单元格内的内容
print(sheet.cell(2,2).value )
# 查看具体有多少行,多少列
print(sheet.nrows,sheet.ncols)
# for i in range(0,sheet.nrows,1):
#     for j in range(0,sheet.ncols,1):
#         print(sheet.cell(i,j).value,end=" ")
#     print()
# path="housing.xls"
# book=xlrd.open_workbook(path)
# sheet=book.sheet_by_index(0)
# nrows=sheet.nrows
# 将换来的表单通过复制复制出一个副本
# book_copy = copy(book)
# 获取第一页
#  sheet_copy = book_copy.get_sheet(0)
# data=["104","123456","liun ","农业银行",12345,"1"]
# for i in range(0,len(data),1):
# 在表单中写入内容
#     sheet_copy.write(nrows,i,data[i])
# 将写好的内容保存
# book_copy.save("housing.xls")

from pyecharts import Bar
# from pyecharts import Pie
#
# def read_excel(filename):
#     book = xlrd.open_workbook(filename)
#     sheet = book.sheet_by_index(0)
#     columns0 = []定义两列表通过列表的append方法将要读取的内容保存到两个列表中日韩返回侧完成读取
#     data0 = []
#     for i in range(1,sheet.nrows,1):
#         columns0.append(sheet.cell(i,2).value)
#         data0.append(sheet.cell(i,4).value)
#     return columns0,data0
#
# def show_bar(columns,data):
#     # //设置柱状图的主标题与副标题
#     bar = Bar("柱状图", "象牙山排行榜")
#     bar.add("余额", columns, data)
#     # //生成本地文件(默认为.html文件)
#     bar.render()
#
# def show_pie(columns,data):
#
#     # // 设置主标题与副标题,标题设置居中,设置宽度为900
#     pie = Pie("饼状图", "象牙山排行榜", title_pos='center', width=900)
#     # // 加入数据,设置坐标位置为【25,50】,上方的colums选项取消显示
#     pie.add("余额", columns, data, center=[25, 50], is_legend_show=False)
#     # // 保存图表
#     pie.render()
#
#
# columns,data = read_excel("test6.xls")
# show_pie(columns,data)

from pyecharts import Scatter
import xlrd

book = xlrd.open_workbook("housing.xls")
sheet = book.sheet_by_index(0)
data1 = []
data2 = []
for i in range(1,sheet.nrows,1):
    data1.append(sheet.cell(i,0).value)
    data2.append(sheet.cell(i,1).value)
print("数据读取完毕!")
print("生成散点图...")
scatter = Scatter("散点图", "经纬度")
# //xais_name是设置横坐标名称,这里由于显示问题,还需要将y轴名称与y轴的距离进行设置
scatter.add("经度与纬度的散点分布", data1,data2,xaxis_name="精度",yaxis_name="维度",yaxis_name_gap=40)
scatter.render()
print("生成完毕!")



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值