【发布时间】:2021-08-14 08:05:29
【问题描述】:
我目前正在处理大量文件,这些文件需要我检查某些字符串的频率。我的第一个想法是将所有文件导入到单个数据集中,并使用 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 准确地生成了我手头工作所需的内容,但它没有提供完整列表,如此链接 (https://imgur.com/xxf1Qnx) 中所示。有没有办法从 Pandas Profiling 中获取完整的词频列表?我已经尝试检查 pandas_profiling 文档 (https://pandas-profiling.github.io/pandas-profiling/docs/master/index.html) 以查看是否有任何我可以做的事情,但到目前为止我还没有看到任何与我的用例相关的内容。
【问题讨论】:
标签: python pandas pandas-profiling