Reputation: 899
I'm Having a csv files with 2 columns named Words and Frequency and want to return the sum of number of words with frequency of 2 and less this is the code I'm trying to use but it says
TypeError: unsupported operand type(s) for +: 'int' and 'str'
df=pd.read_csv('dictionary.csv')
result=(sum(df['word'] if df['freq']<=2))
print("the number of words appearing less than 3 times are :{}".format{reslt})
data sample
Upvotes: 1
Views: 86
Reputation: 862601
If want count number of rows matching condition, so it means number of True
s of mask only use sum
:
result = (df['freq']<=2).sum()
Or:
result = df['freq'].le(2).sum()
Upvotes: 4