由于目前暂时还未学习到python关于数据处理的模块方面的知识,且刚好最近朋友发来一份坐标数据文件(txt格式),让我帮他对其进行筛选,
因此利用了最近刚学过的python文件处理操作以及以前所学的基础知识,用比较笨的方法勉强写了出来。
最终实现了打印出符合目标要求的具体坐标以及总个数
需求:筛选出文件中所含坐标的经纬度都符合某个值的坐标个数
代码:
#!/usr/local/bin/python3
# -*- coding:utf-8 -*-
'''
原始txt文件名称存储为 location_data
'''
a,b,c=0,0,0
temp,temp3,temp4=[],[],[]
with open("location_data2",'w',encoding="utf-8") as f2:
for x in open("location_data",'r',encoding="utf-8").read():
if x=='(' or x==')' or x==' ': #将原始文件中的左右括号以及空格去除,并存入一个新文件 location_data2
continue
f2.write(x)
for line in open("location_data2",'r',encoding="utf-8"):
temp2=line.split(',') #以','分割依次将line放入一个list
temp.extend(temp2)
for i in temp:
temp3.append(float(i))
while a
if float(temp3[2*a])<=1000 and float(temp[2*a+1])<=1000:
temp4.insert(0,float(temp3[2*a]))
temp4.insert(1,float(temp3[2*a+1]))
print(temp4)
b+=1
temp4=[]
a+=1
print(b)