0

I am trying to calculate the RMS of a list of values from an excel file and am having an issue, see the below error message.

Screenshot of the error

My code is as follows

path = (r'BusTest.xlsx')
second_column = dataframe.iloc[:, 2]

line_count = 0  
for row in second_column:    
    rms = [math.sqrt(((sum(float(x) * 9.8) * (float(x) * 9.8)) for x in second_column) / second_column(len))]

The Error states:

TypeError: 'Series' object is not callable

Is there anyone who can assist me with this?

Any help would be greatly appreciated

F Blanchet
  • 1,430
  • 3
  • 21
  • 32
BIAS
  • 1
  • 1
  • 1
    Welcome to StackOverflow. Try to add some example data so people can reproduce an answer for you, [here's](https://stackoverflow.com/questions/20109391/how-to-make-good-reproducible-pandas-examples) a post on how to make a good pandas question. Furthermore, you don't want to loop through a column since its slow, and pandas and numpy have many vectorized solutions for most of our problems – Erfan Jun 22 '19 at 13:08
  • You have a typo in your parentheses in `rms` calculation. Not sure what calculation you want to do exactly, but they are wrong like that. – Valentino Jun 22 '19 at 13:27

1 Answers1

2

So you want the root mean square error of a dataframe column?

  1. get the values:

second_column = dataframe.iloc[:, 2].astype("float")

  1. compute mean:

mean = second_column.mean()

  1. compute mse and take root:

n_values=len(second_column)

mse = sum((second_column-mean)**2)/(n_values-1)

rmse = np.sqrt(mse)

N.B.:

As far as the error you got: a pandas series is not an iterable, is an object. If you take the values contained in that object than got yourself an iterable and you can use it in a for-loop; e.g. second_column.values is an iterable

RMSE of a series is not an array, it's a single value, therefore a list comprehension won't get you there.

Community
  • 1
  • 1