【发布时间】:2020-01-06 16:31:34
【问题描述】:
我是 Pandas 的新手。
我有一个 excel 文件,里面有 10 张纸。我正在尝试to achieve this。
由于没有提供关于该问题的答案,我将使用此方法检查 DataFrame 行中的字符串是否包含 excel 表中的单词:
file = pd.read_excel(open('config_values.xlsx', 'rb'),
sheet_name='ContainsFree')
使用
first_sheet = '|'.join(file)加入Excel工作表中的所有行使用:
df['Contains Language'] = df.Search_Query.str.contains(first_sheet, regex=True)
但是,当我使用 '|'.join(file) 时,我得到的是 excel 表的第一行而不是连接的字符串:
excel_sheet_1
gratuit
free
gratis
...
'|'join.(file) 之后我得到:
gratuit
预期:
gratuit|free|gratis
为了加入 Excel 工作表中的所有行,我做错了什么?
感谢您的建议。
【问题讨论】:
-
使用
read_excel时不需要open -
谢谢,但我仍然无法使用
'|'.join(file)将所有行加入到单个字符串中,我只能获得工作表的第一个条目。