无法在我的数据框列中找到子字符串的匹配项

问题描述 投票:0回答:1
def process_and_predict(folder_path):
    image_files = os.listdir(folder_path)
    results_df = pd.DataFrame(columns=['name', 'prediction', 'actual'])
    
    for image_file in image_files:
        #some pre processing
        str1 = str(image_file)#converting name to string, just a precaution not really necessary since i have confirmed it is the same
        str1 = str1.strip()
        st.write("string ",str1)
        actual = df.loc[df['Image_filename'].str.contains(str1), 'BIRADS'].values[0]

我有一个数据框,其中包含“Image_filename”列中的文件路径 我正在迭代一些测试图像并尝试找到与 image_file 匹配的行并提取“BIRADS”列值

示例 - “inst/BIRADS 2/birads - 2 (11).bmp”这是我的 df['Image_filename'] 中的值

现在在迭代时,image_file(制作成 str1)获取值 - 'birads - 2 (11).bmp'

理想情况下,上面的代码应该给我一个匹配,但事实并非如此,这是我收到的消息 -

UserWarning: This pattern is interpreted as a regular expression, and has match groups. To actually get the groups, use str.extract.new_info['Image_filename'].str.contains(x)

这很奇怪,因为当 str1 类似于“case001.png”时,相同的代码可以毫无问题地进行匹配

“Image_filename”中的匹配条目为 -“BrEaST-Lesions_USG-images_and_masks/case001.png”

python pandas string matching
1个回答
0
投票

尝试:

.new_info['Image_filename'].str.contains(x, regex=False)

默认情况下,x 被解释为正则表达式,其中

(...)
具有特殊含义。请参阅此处

© www.soinside.com 2019 - 2024. All rights reserved.