title: how do i find the occurrence and percentage of occurance of a word in a string ; how to fix error
body: <p>basically i have this excel file that i uploaded to python, i made a new column which identified if a word was in each row and if it was in a row then it would come out as true, if not false. So i have this new column and im trying to find the percentage of true and false. Later i will try to make a table separating all the ones that are true and false. I need help with the percentage one first. I am a beginner like i started this last week</p>
  
  <p>so for the percentage problem i decided to first create a code to count the occurrence of the word "true" and "false" in the column and then i would have just did some math to get the percentages but i didn't get past counting the occurrence. The product of the codes below were 0 and thats not what is suppose to display. </p>
  
  <pre><code>import pandas as pd
  import xlrd
  df = pd.read_excel (r'C:\New folder\CrohnsD.xlsx')
  print (df)
  df['has_word_icd'] = df.apply(lambda row: True if 
  row.str.contains('ICD').any() else False, axis=1)
  print(df['has_word_icd'])
  #df.to_excel(r'C:\New folder\done.xlsx')
  test_str = "df['has_word_icd']"
  counter = test_str.count('true')
  print (str(counter))
  </code></pre>
  
  <p>this is the updated version and it still gives me 0, i cannot change df['has_word_icd'] because thats how the variable is introduced initially </p>
  
  <pre><code>import pandas as pd
  import xlrd
  df = pd.read_excel (r'C:\New folder\CrohnsD.xlsx')
  print (df)
  df['has_word_icd'] = df.apply(lambda row: True if 
  row.str.contains('ICD').any() else False, axis=1)
  print(df['has_word_icd'])
  #df.to_excel(r'C:\New folder\done.xlsx')
  
  test_str = (df['has_word_icd'])
  
  count = 0
  for i in range(len(test_str)):
     if test_str[i] == 'true':
          count += 1
    i += 1
  
  print(count)
  </code></pre>
  
  <p>both gave me the same result</p>
  
  <p>please help me, the output from both codes is "0" and it shouldn't be that. Somebody help me get a code that just directly gives me the percent of the "true" &amp; "false"</p>