JetCorey JetCorey - 6 months ago 14
Python Question

iPython:Using Pandas, How do I combine multiple text files to find reacurring usernames?

I'm using pandas to count recurring usernames from 2 different large text files. How do I get my code to analyze the data from both files at the same time? Right now I have only been able to run one text file so nothing is occurring more than once.

Here is my Code:

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

Answer

Combine files like this

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])
Comments