Skip to content

Instantly share code, notes, and snippets.

@dinukasal
Last active January 6, 2020 09:25
Show Gist options
  • Save dinukasal/2df4e57fd25e7f6cab0325f53c13f278 to your computer and use it in GitHub Desktop.
Save dinukasal/2df4e57fd25e7f6cab0325f53c13f278 to your computer and use it in GitHub Desktop.
Count similar strings in an array of strings
import csv
import pandas as pd
lines = []
with open('search_kpi.csv') as csvfile:
readCSV = csv.reader(x.replace('\0', '') for x in csvfile)
for row in readCSV:
lines.append(row[1])
df = pd.DataFrame({'term': lines})
print(df)
print(df.groupby(['term']).size().sort_values(ascending=False)[:20])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment