pythoncsvweb-crawlerrms

How to find rms value of every row from a csv file using python spider IDE?


I have written this code for reading the csv file

import numpy as np  
import pandas as pd

ratings_data = pd.read_csv("matrix1.csv")  
ratings_data.head()  

Now I want the rms value of each row. Is there any way? rms means root mean square.


Solution

  • Until someone or I come up with a built-in/one liner:

    import math
    import pandas as pd
    
    ratings_data = pd.read_csv("matrix1.csv")
    for index, row in ratings_data.iterrows():
        print(
            math.sqrt(
                ((ratings_data['col_a'] ** 2) + (ratings_data['col_b'] ** 2) +
              (ratings_data['col_c'] ** 2))/3
            )
        )