python - iPython :Using Pandas, 如何组合多个文本文件来查找重复出现的用户名?

标签 python python-3.x pandas

我正在使用 pandas 来计算 2 个不同的大型文本文件中重复出现的用户名。如何让我的代码同时分析两个文件中的数据?现在我只能运行一个文本文件,所以没有任何事情发生超过一次。

这是我的代码:

import pandas as pd
fixed_df = pd.read_csv('sample.txt', sep=';', encoding='latin1')
fixed_df['User Name'].value_counts().nsmallest()

最佳答案

像这样合并文件

fixed_df1 = pd.read_csv('sample1.txt', sep=';', encoding='latin1')
fixed_df2 = pd.read_csv('sample2.txt', sep=';', encoding='latin1')
fixed_df = pd.concat([fixed_df1, fixed_df2])

关于python - iPython :Using Pandas, 如何组合多个文本文件来查找重复出现的用户名?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37487829/

相关文章:

python - python中根据数据框中的列值循环文本数据

python - 使用多处理将方法并行应用于对象列表

python-3.x - Requests.get(zipfile) 获取 'BadZipFile: File is not a zip file"

python - 使用不同的 y 轴绘制 pandas 数据框中的条形图和线条

python-3.x - Python 3 枚举元组相等总是失败

python-3.x - 为什么 Python 3.8.3 的单元测试覆盖被禁用?

mysql - 'latin- 1' codec can' t 编码字符 u'\u2014' 在位置 23 : ordinal not in range(256)

python - 使用 ctypes 时 Dll 函数的名称错误

python - 将包含字母的字符串转换为日期时间

python - 从深度图计算视野