I have a 2D matrix with 13 rows and 13 columns (with headers except for the first column) named correl
in Python. This correl
matrix was generated from a DataFrame
and I wish to populate a matrix correlation
with multiple correl
. For example:
correlation=[]
correl=df.corr()
correlation=correlation.append(correl) #correlation is not a DataFrame
The reason why I use the correlation=[]
it is because I wish to populate the correlation
with multiple correlation tables. That is why I use the append
since this is in a loop.
Now I wish to export this correlation matrix in a csv file. I do:
with open("C:\destinationfolder\file.csv", "wb") as f:
writer = csv.writer(f)
writer.writerows(correlation)
I get this error:
raise KeyError('no item named %s' % com.pprint_thing(item))
KeyError: u'no item named 0'
Why? My guess is that I don't have a header for the first column... is there an easier way to export my correlation table to csv?