我已经导入了多个XML文件。如果您从一个XML文件中以字符串格式打印一个子级,那么您将得到类似以下内容:'http://www.springframework.org/schema/integration/jms}message-driven-channel-adapter',位于0xb97260d9e8>' 。我定义了一个数据框,其中一个单元格包含单词“ message-driven-channel-adapter”。如果孩子(如前所述)包含在我的数据框中存在的单词,那么我想获取输出(例如True或1)。是否可以检查孩子在我的数据框中是否包含某个单元格?
import pandas as pd
import xml.etree.ElementTree as et
import os
#defines the paths of the XML files
directory = os.getcwd() + "\\Import_XML_files"
directory2 = os.getcwd() + "\\Import_XML_files\\{}"
#importing excel file
excelname = os.getcwd() +'\\Information_Blocks_(Transformation).xlsx'
excelfile = pd.read_excel(excelname)
#define starting- and endingblocks
startingblocks = excelfile.iloc[2:,1].reset_index(drop=True)
endingblocks = excelfile.iloc[2:,4].reset_index(drop=True)
#runs through XML files
for filename in os.listdir(directory):
#defines how to read the XML file
base_path = os.path.dirname(os.path.realpath(__file__))
xml_file = os.path.join(base_path, directory2.format(filename))
tree = et.parse(xml_file)
root = tree.getroot()
#reads XML file
for child in root:
if str(child).find(startingblocks) > 0:
pass
我希望在if语句中使用它。如果孩子在我的数据框中包含一个单元格,则输出= True或1