我是python的初学者,我有2个excel xlsm文件。第一个文件将两列数据组合成一个字典,我想将该字典的键与第二个文件中的数据列表进行比较。如果两个数据中的键和“行情指示器”是等效的,则“行情指示器将更改为与键配对的值。我不确定如何执行此过程,我真正要做的就是制作字典并进行比较
import itertools #module that includes functions to work with iterable data
import pandas as pd # this allows for data manipulation and analysis to and
from excel
from pandas import ExcelWriter
from pandas import ExcelFile
import pickle # its a module that publishes objects or other data so they
can be saved to a file and opened again later
import os.path # allows to work/manipulate on file names and paths
import xlrd # A module that allows python to read excel files
import xlwings as xw # module that helps to tie python, excel, and pandas
to take data from a database, manipulate it and present it in a spreadsheet
from tkinter import * # standard GUI
from tkinter.filedialog import askopenfilename # module with open and save
functions
import re # a module that helps to match or find sets of strings
import datetime
#Accessing the ticker col
print("Accessing PerfData")
performancefilename = r"C:\Users\opera\Documents\Evan
Projects\matrix\PerfData.xlsm"
data = xlrd.open_workbook(performancefilename)
sheet = data.sheet_by_index(0)
#Storing ticker values in colTicker
colTicker = sheet.col_values(1, 1, 6000)
#Accessing AA and Z list from Master List
print("Accesing nessecary values from the Master List")
bondfilename = r'C:\Users\opera\Documents\Evan Projects\matrix\P&L
061118.xlsm'
book = xw.Book(bondfilename)
sheet = book.sheets['Master List']
translateFrom = sheet.range("Z2:Z1500").value
translateTo = sheet.range("AA2:AA1500").value
#Pairing Z and AA list in a dictionary
oldNew = {}
for From, To in zip(translateFrom, translateTo):
oldNew[From] = To
#Comparing master list and ticker col
for key in oldNew:
if key in colTicker:
print (colTicker)