Python 有没有可能从Pandas Profiling中获得词频的详细列表?

Python 有没有可能从Pandas Profiling中获得词频的详细列表?,python,pandas,pandas-profiling,Python,Pandas,Pandas Profiling,我目前正在处理大量文件,这些文件要求我检查某些字符串的频率。我的第一个想法是将所有文件导入到单个数据集中,并使用for循环使用以下代码检查所有文件中的字符串 # Define an empty dataframe to append all imported files to df = pd.DataFrame() new_list = [] # If text file is import successfully append the resulting dataframe to df.

我目前正在处理大量文件,这些文件要求我检查某些字符串的频率。我的第一个想法是将所有文件导入到单个数据集中,并使用for循环使用以下代码检查所有文件中的字符串

 # Define an empty dataframe to append all imported files to
df = pd.DataFrame()
new_list = []

# If text file is import successfully append the resulting dataframe to df. If an exception occurs append "None" instead.
# "`" was chosen as the delimiter to ensure that each file is saved to a single row.
for i in file_list: 
    try: df_1 = pd.read_csv(f"D:/Admin/3. OCR files/OCR_Translations/{i}", delimiter = "`") 
    df = df.append(df_1) new_list.append(f"D:/Admin/3. OCR files/OCR_Translations/{i}") 
except: 
    df = df.append(["None"])                
    new_list.append("None")

df = df.T.reset_index()

# Search the dataset for the required keyword
count = 0

for i in df["index"]:
    if "Keyword1" in i:
        count += 1
这最终以失败告终,因为无法保证字符串在这些文件中的拼写正确,因为所讨论的文件是由OCR程序生成的(而且所讨论的文件是泰语的)

Pandas Profiling生成手头工作所需的内容,只是它没有给出完整的列表,如本链接()中所示。有没有办法从熊猫评测中获取词频的完整列表?我已经检查了pandas_评测文档()以查看是否有什么我可以做的,但到目前为止,我还没有看到与我的用例相关的任何内容。

您可能不需要pandas来计算文件中的单词出现次数

import collections

word_counter = collections.Counter()

for i in file_list:
    with open(f"D:/Admin/3. OCR files/OCR_Translations/{i}") as f:
        for line in f:
            words = line.strip().split()  # Split line by whitespaces.
            word_counter.update(words)  # Update counter with occurrences.


print(word_counter)
您可能还对计数器上的方法感兴趣


此外,如果确实需要,还可以将
计数器
转换为数据帧;这只是一个带有特殊效果的口述。

非常感谢您的回答。原来这正是我要找的!