2 Star 3 Fork 2

starsgod/CSDN资源库

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
经纬度处理.py 996 Bytes
一键复制 编辑 原始数据 按行查看 历史
starsgod 提交于 2021-04-19 17:05 +08:00 . update 经纬度处理.py.
import xlwt
f = open('研究院校经纬度.txt','r',encoding='utf-8')
book = xlwt.Workbook(encoding='utf-8',style_compression=0)
sheet = book.add_sheet('mysheet',cell_overwrite_ok=True) # 第一个参数为工作表名称,第二参数用于确认同一个cell单元是否可以重设值
sheet.write(0,0,"name") # 在第一行第一列写入字段name
sheet.write(0,1,"jingdu") # 在第一行第二列写入字段jingdu(经度)
sheet.write(0,2,"weidu") # 同上
datas = f.readlines() # 读取文件中的所有行,默认格式列表
length = len(datas) # 统计行数
for i in range(1, length+1):
line = datas[i-1].strip('\n').split(',') #strip去除每行最后的换行符,然后使用split以逗号分割每行字符串为列表,
words = len(line) # line列表的元素个数
for j in range(words):
sheet.write(i, j, line[j]) # 循环写入所有数据
print("结束")
book.save('经纬度.xls') # 保存为xls文件
f.close()
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/starsgod/csdn-resource-library.git
git@gitee.com:starsgod/csdn-resource-library.git
starsgod
csdn-resource-library
CSDN资源库
master

搜索帮助