How do I calculate the mean of a column

后端 未结 5 1097
花落未央
花落未央 2020-12-25 10:42

Anyone know how can I calculate the mean of one these columns (on linux)??

sda               2.91    20.44    6.13    2.95   217.53   186.67    44.55     0.         


        
5条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-25 11:32

    You can use python for that, is available in Linux.

    If that comes from a file, take a look at this question, just use float instead.

    For instance:

    #mean.py 
    def main():
        with open("mean.txt", 'r') as f:
            data = [map(float, line.split()) for line in f]
    
        columnTwo = []
        for row in data:
            columnTwo.append( row[1] )
    
        print  sum(columnTwo,0.0) / len( columnTwo )
    
    
    
    if __name__=="__main__":
        main()
    

    Prints 14.38

    I just include the data in the mean.txt file, not the row header: "sda"

提交回复
热议问题