想象一下,您有这些文件路径,您想从以下位置获取不带扩展名的文件名:
relfilepath
0 20210322636.pdf
12 factuur-f23622.pdf
14 ingram micro.pdf
19 upfront.nl domein - Copy.pdf
21 upfront.nl domein.pdf
Name: relfilepath, dtype: object
我想出了以下内容,但这给了我一个问题,即对于第一项,它变成了一个输出“20210322636.0”的数字。
from pathlib import Path
for i, row in dffinalselection.iterrows():
dffinalselection['xmlfilename'][i] = Path(dffinalselection['relfilepath'][i]).stem
dffinalselection['xmlfilename'] = dffinalselection['xmlfilename'].astype(str)
这是错误的,因为它应该是 '20210322636'
请帮忙!