Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/290.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中单词搜索和计数器函数的重新索引错误,即使没有重复项_Python_Pandas_Pathlib - Fatal编程技术网

python中单词搜索和计数器函数的重新索引错误,即使没有重复项

python中单词搜索和计数器函数的重新索引错误,即使没有重复项,python,pandas,pathlib,Python,Pandas,Pathlib,我是python新手,试图了解如何进行故障排除。我问了一个这样的问题,但即使答案对其他用户有效,它也给了我一个重新索引的错误,即使脚本单词搜索没有重复项 from pathlib import Path import pandas as pd def get_files_to_parse(start_dir : str) -> list: files = [f for f in Path(start_dir).glob('*.csv')] return file

我是python新手,试图了解如何进行故障排除。我问了一个这样的问题,但即使答案对其他用户有效,它也给了我一个重新索引的错误,即使脚本单词搜索没有重复项

from pathlib import Path
import pandas as pd

def get_files_to_parse(start_dir : str) -> list:
    
    files = [f for f in Path(start_dir).glob('*.csv')]
    return files

def search_multiple_files(list_of_paths : list,key_words : list) -> pd.DataFrame:
    dfs = []
    for file in list_of_paths:
        df = pd.read_csv(file)
        word_df = df['transcript'].str.extractall(f"({'|'.join(key_words)})")\
                        .droplevel(1,0)\
                        .reset_index()\
                        .rename(columns={'index' : f"{file.parent}_{file.stem}"})\
                        .set_index(0).T
        dfs.append(word_df)
    return pd.concat(dfs)
    
    
files = get_files_to_parse('C:/Users/jj/Desktop/Bulk_Wav_Completed')
search_multiple_files(files,['nation','nation wide', 'trupanion', 'pet plan', 'best', 'embrace','healthy paws', 'pet first', 'pet partners','lemon',
      'AKC','kennel club','club','american kennel','american',
      'kennel','figo', 'companion protect', 'true companion',
      'true panion', 'trusted pals','partners' 'lemonade', 'partner',
      'wagmo','vagmo','bivvy','bivy','bee' '4paws','paws',
      'pets best','pet best'])
错误是-

Traceback (most recent call last):

  File "<ipython-input-31-ad2470b2f620>", line 7, in <module>
    'pets best'])

  File "<ipython-input-28-e357b92daa9f>", line 19, in search_multiple_files
    return pd.concat(dfs)

  File "C:\Users\jj\AppData\Local\Continuum\anaconda3\lib\site-packages\pandas\core\reshape\concat.py", line 298, in concat
    return op.get_result()

  File "C:\Users\jj\AppData\Local\Continuum\anaconda3\lib\site-packages\pandas\core\reshape\concat.py", line 516, in get_result
    indexers[ax] = obj_labels.get_indexer(new_labels)

  File "C:\Users\jj\AppData\Local\Continuum\anaconda3\lib\site-packages\pandas\core\indexes\base.py", line 3172, in get_indexer
    "Reindexing only valid with uniquely valued Index objects"

InvalidIndexError: Reindexing only valid with uniquely valued Index objects
回溯(最近一次呼叫最后一次):
文件“”,第7行,在
“宠物最好”])
文件“”,第19行,搜索多个文件
返回pd.concat(dfs)
concat中的文件“C:\Users\jj\AppData\Local\Continuum\anaconda3\lib\site packages\pandas\core\reforme\concat.py”,第298行
返回操作获取结果()
文件“C:\Users\jj\AppData\Local\Continuum\anaconda3\lib\site packages\pandas\core\remode\concat.py”,第516行,在get\U结果中
索引器[ax]=对象标签。获取索引器(新标签)
文件“C:\Users\jj\AppData\Local\Continuum\anaconda3\lib\site packages\pandas\core\index\base.py”,第3172行,在get\U索引器中
“重新索引仅对唯一值索引对象有效”
InvalidIndexError:重新索引仅对唯一值的索引对象有效
请参考我关于SO的问题和用户Umar H的答案,我在这里进行故障排除