我有两个CSV文件。
第一个列表如下所示:
('Rubus idaeus', '10.0', '56.0')
('Neckera crispa', '9.8785', '56.803')
('Dicranum polysetum', '9.1919', '56.0456')
('Sphagnum subnitens', '9.1826', '56.6367')
('Taxus baccata', '9.61778', '55.68833')
('Sphagnum papillosum', '9.1879', '56.0442')
列为“物种”、“经度”和“纬度”。
它们是在实地进行的观察。
另一个文件也是CSV文件。一种与真品相似的测试。看起来是这样的:
{'y': '58.1', 'x': '22.1', 'temp': '14'}
{'y': '58.2', 'x': '22.2', 'temp': '10'}
{'y': '58.3', 'x': '22.3', 'temp': '1'}
{'y': '58.4', 'x': '22.4', 'temp': '12'}
{'y': '58.5', 'x': '22.5', 'temp': '1'}
{'y': '58.6', 'x': '22.6', 'temp': '6'}
{'y': '58.7', 'x': '22.7', 'temp': '0'}
{'y': '58.8', 'x': '22.8', 'temp': '13'}
{'y': '58.9', 'x': '22.9', 'temp': '7'}
两个文件都很长。你知道吗
我有了观测结果,现在我想在包含气候数据的文件中找到最接近的较低的数字,然后将该行附加到另一行,这样输出就变成:
('Dicranum polysetum', '9.1919', '56.0456', 'y': '9.1', 'x': '56.0', 'temp': '7')
我尝试通过使用DictReader
遍历CSV文件来创建嵌套循环,但是嵌套速度非常快。整个过程需要大量的循环。
有人知道什么方法吗?你知道吗
我目前的代码很差,但我尝试了几种循环方式,我认为我的整个方法有一些根本性的错误。你知道吗
import csv
fil = csv.DictReader(open("TestData.csv"), delimiter=';')
navn = "nyDK_OVER_50M.csv"
occu = csv.DictReader(open(navn), delimiter='\t')
for row in fil:
print 'x=',row['x']
for line in occu:
print round(float(line['decimalLongitude']),1)
if round(float(line['decimalLongitude']),1) == row['x']:
print 'You did it, found one dam match'
这是我的两个文件的链接,所以你不必编造任何数据,以防你知道什么可以推动我前进。你知道吗
https://www.dropbox.com/s/lmstnkq8jl71vcc/nyDK_OVER_50M.csv?dl=0https://www.dropbox.com/s/v22j61vi9b43j78/TestData.csv?dl=0
致以最诚挚的问候, 马蒂亚斯
这是一个使用
numpy
计算每个数据项到x,y
点的欧氏距离的解决方案,并将该项与x,y
数据元组中距离最小的数据连接起来。你知道吗输出:
注意:距离不是很近,但这可能是因为
.csv
文件中没有完整的x,y
点网格。你知道吗因为你说没有缺失的温度数据点,那么解决问题就容易多了:
相关问题 更多 >
编程相关推荐