#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    2
    Rep Power
    0

    Load a CSV file to a list


    Hi,

    I'm trying to correlate several variables with the following code :

    Code:
    from numpy import corrcoef
    from pylab import pcolor, show, colorbar, xticks, yticks
    import csv
    
    data = csv.reader(open("sales_variables.csv", "rU"))
    
    
    # plot the correlation matrix
    D = corrcoef(data)
    
    pcolor(D)
    colorbar()
    yticks(arange(0.5,10.5),range(0,10))
    xticks(arange(0.5,10.5),range(0,10))
    show()
    To get this working I need to figure a way of getting the CSV object into a list of values that corrcoef is expecting.

    Any ideas? I@m very new to Python programming so please excuse my ignorance.
  2. #2
  3. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,841
    Rep Power
    480
    You'll need to convert the strings to numbers.

    (this improved answer is less stupid)
    Last edited by b49P23TIvg; November 29th, 2012 at 10:28 AM. Reason: Remove stupid answer
    [code]Code tags[/code] are essential for python code and Makefiles!
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    2
    Rep Power
    0
    I got it working by wrapping the data with list ie

    d = corrcoef(list(data))

    Thanks

    Lee

IMN logo majestic logo threadwatch logo seochat tools logo