I have a .tsv data file. I want to print the count of strings in a certain column. The column looks like this:
column1
A aaa
A, C c
C
D
E ee,F
A aaa, B, C cc
F
E ee
I want distinct counts of A,B,C, A aaa etc. But in the column, there are sometimes spaces after the ",". So my code counts "B" and " B" differently. This is the code I am currently using:
import pandas as pd
import os
# Import data from file into Pandas DataFrame
data= pd.read_csv("data.tsv", encoding='utf-8', delimiter="\t")
pd.set_option('display.max_rows', None)
out = data['Column1'].str.split(',', expand=True).stack().value_counts()
print (out)
Any leads are appreciated.