title: How to rid of some of the cells in the Dataframe with strings and 'inf' values?
body: <p>I'm new to pandas and data science in general. I have the data which I have to get the mean of, but the data is very big(around 15000 rows), and some of the cells of the data frame has strings( like #NEXT? which gives the value -inf when calculating the mean) and some when values when dividing( some values are zeros) give NaN but some of them gives values 'inf' so the total mean comes as 'inf'. I want to get rid of these types of values. Can someone please tell me how to overlook these values when operating on a column?</p>
  <p>I tried many things, like looping over the entire column of a data frame and getting rid of the values.</p>
  <pre><code>x_wto_inf = []
  for i in reports.iterrows():
      x = reports['y_cost'][i] / reports['z_calls'][i]
      if x == 'inf':
          break
      else:
          x_wto_inf.append(x)
  x_wto_inf_df = pd.DataFrame(x_wto_inf, columns = ['x_wto_inf'])
  </code></pre>
  <p>This gives me an error.</p>
  <pre><code>ValueError: Can only tuple-index with a MultiIndex
  </code></pre>
  <p>I also tried to just read all the values of the column in the data frame and then putting that into the loop which is given below.</p>
  <pre><code>y_cost_var = reports['y_cost']
  y_cost_var_val = y_cost_var.values
  y_cost_var_val
  
  
  z_calls_var = reports['z_calls']
  z_calls_var_val = z_calls_var.values
  z_cost_var_val
  </code></pre>
  <p>and then dividing the values as arrays but it's also giving me an error.</p>
  <pre><code>IndexError: only integers, slices (`:`), ellipsis (`...`), NumPy.newaxis (`None`), and integer or boolean arrays are valid indices
  </code></pre>
  <p>can someone please help me with this? I will forever be grateful for it. Thank you.</p>
  <blockquote>
  <p>UPDATE</p>
  </blockquote>
  <p>I Tried this piece of code,</p>
  <pre><code>reports_Copy1 = reports_Copy.replace([np.inf, -np.inf], 0)
  reports_Copy1 = reports_Copy.replace('#NEXT?', 0)
  reports_Copy1.iloc[3177]
  reports_Copy1.iloc[3184]
  </code></pre>
  <p>when printing these results, it shows all these values as zero, as you can see below,</p>
  <pre><code>responsiveness                                         0
  </code></pre>
  <p>but taking the mean of it still gives me <code>'-inf'</code></p>
  <p>I don't know how to solve this, can someone please help?</p>