Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/321.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 将excel行连接到要在DataFrame中使用的单个字符串_Python_Excel_Pandas - Fatal编程技术网

Python 将excel行连接到要在DataFrame中使用的单个字符串

Python 将excel行连接到要在DataFrame中使用的单个字符串,python,excel,pandas,Python,Excel,Pandas,我对熊猫不熟悉 我有一个excel文件,里面有10张表格。我正在努力 由于该问题未提供答案,我将使用此方法检查DataFrame行中的字符串是否包含excel工作表中的单词: file = pd.read_excel(open('config_values.xlsx', 'rb'), sheet_name='ContainsFree') 使用first_sheet='|''连接excel工作表中的所有行。连接(文件) 使用: 但是,当我使用“|”.jo

我对熊猫不熟悉

我有一个excel文件,里面有10张表格。我正在努力

由于该问题未提供答案,我将使用此方法检查DataFrame行中的字符串是否包含excel工作表中的单词:

file = pd.read_excel(open('config_values.xlsx', 'rb'),
                     sheet_name='ContainsFree')
  • 使用
    first_sheet='|''连接excel工作表中的所有行。连接(文件)

  • 使用:

  • 但是,当我使用
    “|”.join(file)
    时,我得到的是excel工作表的第一行,而不是连接的字符串:

    excel工作表1

    gratuit
    free
    gratis
    ...
    
    在加入(文件)之后,我得到:

    gratuit
    
    预期:

    gratuit|free|gratis
    
    为了连接excel工作表中的所有行,我做错了什么

    谢谢您的建议。

    试试:

    file = pd.read_excel('config_values.xlsx', sheet_name='ContainsFree', header=None)
    '|'.join(file[0].astype(str))
    
    'gratuit|free|gratis'
    

    使用
    read_excel
    时,您不需要
    open
    谢谢,但我仍然无法使用
    “|”将所有行合并到一个字符串中。join(file)
    ,我只得到工作表的第一个条目。这很有效,只是添加了
    文件=“|”。join(file[0])
    ,谢谢。您介意帮我加入
    ints
    ?我得到一个错误:
    TypeError:sequence item 0:expected str instance,int found
    ,当我使用
    containsYear='|'。join(str(containsYear[0])
    我得到
    0 | | | | 2 | 0 | 1 | 0
    。当我试图加入
    200120022003,
    @JonasPalačionis时,我编辑了我的答案。尝试添加
    astype(str)
    file = pd.read_excel('config_values.xlsx', sheet_name='ContainsFree', header=None)
    '|'.join(file[0].astype(str))
    
    'gratuit|free|gratis'