Python搜索和附加2个csv文件

Python搜索和附加2个csv文件,python,csv,data-cleaning,Python,Csv,Data Cleaning,我有2个CSV文件。第一个文件包含美国所有州的列表,但在经度和纬度列中缺少值。我发现了另一个CSV文件,其中包含美国所有州的所有经度和纬度值 我现在要做的是循环遍历第一个文件中的'Location'列,将其与第二个文件中的'Location'列匹配,然后获取其经度和纬度的相应值。之后,我需要将这些值附加到第一个文件的经度和纬度列中 目前,我拥有的是: aviationdata = pd.read_csv('AviationData.csv', sep = ',', header = 0, enc

我有2个CSV文件。第一个文件包含美国所有州的列表,但在经度和纬度列中缺少值。我发现了另一个CSV文件,其中包含美国所有州的所有经度和纬度值

我现在要做的是循环遍历第一个文件中的'Location'列,将其与第二个文件中的'Location'列匹配,然后获取其经度和纬度的相应值。之后,我需要将这些值附加到第一个文件的经度和纬度列中

目前,我拥有的是:

aviationdata = pd.read_csv('AviationData.csv', sep = ',', header = 0, encoding = 'iso-8859-1') #this is the first file
location = pd.read_csv('location.csv') #this is the 2nd file

import csv

with open('location.csv', 'r') as loc:
    locationfile = loc.read()

for i in range(len(aviationdata['Location'])):
    currentlocation = aviationdata['Location'].iloc[i]
    axis = []
    for i in currentlocation:
        if i in aviationdata['Location']:
   ... #i do not know how to continue from here
我不知道如何找到代码来比较location字段,从location.csv中提取经度和纬度代码,并将它们相应地附加到aviationdata中的经度和纬度列

这些是第一个文件aviationdata的字段


这些是第二个文件位置的字段

这看起来是一个很好的合并工作

假设两个数据帧中的位置列在大小写和间距方面完全相同

一,。从航空数据中获取所有感兴趣的列

aviationdata = aviationdata[["Location", "Country", "Make", "Weather.Condition", "Year", "Month"]]
二,。现在将航空数据与列名称位置上的currentLocation数据框合并

aviationdata = aviationdata.merge(currentlocation, on=['Location'])

aviationdata.head(10)

请不要发布代码、数据或回溯的图像。复制并粘贴为文本,然后将其格式化为代码选择它并键入ctrl-k。。。你的问题是什么?请看,@AMC我已经编辑了这个问题。