none
Read-in CSV and Calculate Average Value RRS feed

  • Question

  • I've got a csv file which I'm reading in but need to calculate the average value of the second column (CPU). It's in the following format:

    Date              CPU
    ----              -----
    01/09/2014        25.3
    02/09/2014        22.3
    03/09/2014        26.2
    04/09/2014        22.1

    I basically need the average CPU for the month. Any advice?

    Thanks in advance
    Adam

    Thursday, September 18, 2014 7:58 AM

Answers

  • Hi,

    In powershell do the following.

    Import the csv into a variable I.E

    $CPU = import-csv CSVFILE.csv

    then use the measure command on the CPU column

    $CPU.cpu | measure -average | select average

    That should do the trick

     

    • Marked as answer by Adam-M Thursday, September 18, 2014 11:58 AM
    Thursday, September 18, 2014 10:26 AM
  • @'
    "Date","CPU"
    "01/09/2014","25.3"
    "02/09/2014","22.3"
    "03/09/2014","26.2"
    "04/09/2014","22.1"
    '@ | sc test.csv
    
    (Import-Csv test.csv | measure CPU -Average).Average
    
    23.975


    [string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "

    Thursday, September 18, 2014 10:28 AM

All replies

  • hi ,

    you Can do with performance  monitor . set new data collector for one month it will give report of one month


    Abhinav

    Thursday, September 18, 2014 10:16 AM
  • The data is exported from a vCenter using PowerCLI so I'm afraid that approach won't work. Thanks though Abhinav.
    Thursday, September 18, 2014 10:19 AM
  • Hi,

    In powershell do the following.

    Import the csv into a variable I.E

    $CPU = import-csv CSVFILE.csv

    then use the measure command on the CPU column

    $CPU.cpu | measure -average | select average

    That should do the trick

     

    • Marked as answer by Adam-M Thursday, September 18, 2014 11:58 AM
    Thursday, September 18, 2014 10:26 AM
  • @'
    "Date","CPU"
    "01/09/2014","25.3"
    "02/09/2014","22.3"
    "03/09/2014","26.2"
    "04/09/2014","22.1"
    '@ | sc test.csv
    
    (Import-Csv test.csv | measure CPU -Average).Average
    
    23.975


    [string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "

    Thursday, September 18, 2014 10:28 AM