0

For this program as below:

import numpy as np
import pandas as pd

np.set_printoptions(formatter='float')
np.random.seed(1)
dataset = pd.read_csv("/Users/Akshita/Desktop/EE660/donor_raw_data_medmean.csv",header=None)
print("Number of samples: {0}".format(dataset.shape[0]))
print("Number of features: {0}".format((dataset.shape[1])-1))

# Separate data and label
X_label = dataset[:][0]
feature_number = list(range(1,61))
X_data = dataset[feature_number]

meanVectors = []

for c in list(range(2)):
    meanVectors.append(np.mean(X_data[X_label==c], axis=0))
    print('Mean Vector class {0}:{1}' .format(c,(meanVectors[c])))

My output is:

Number of samples: 19373
Number of features: 60
Mean Vector class 0:
1        70.719718
2        60.037559
3         0.107512
..
..
58       66.634272
59       13.971254
60        4.748826
dtype: float64
Mean Vector class 1:
1        75.575087
2        60.844005
3         0.145518
..
..
58       71.436554
59       12.092189
60        6.006985

How can I get the output a simple [75.575087, 60.844005, 0.145518...6.006985] and the same for the next?

hpaulj
  • 221,503
  • 14
  • 230
  • 353
  • maybe http://stackoverflow.com/questions/24644656/how-to-print-dataframe-without-index – furas Jan 31 '16 at 01:04
  • Clarification: Do you want these displayed in this format "[75.575087, 60.844005, 0.145518...6.006985]" or in the format that is currently being displayed, but without the index numbers on the left edge? – Robert Rodkey Jan 31 '16 at 01:49
  • @furas Let me try the link and let you kind folks know if it worked. – AllThingsScience Jan 31 '16 at 02:26
  • I have tried every possible combination to patch "index= False" to an existing statement in the code. Python gives me different errors for all combinations. – AllThingsScience Jan 31 '16 at 02:31

1 Answers1

0

It looks like meanVectors[c] should return a Series object, which has a tolist function.

for c in list(range(2)):
    meanVectors.append(np.mean(X_data[X_label==c], axis=0))
    print('Mean Vector class {0}:{1}' .format(c,(meanVectors[c].tolist())))
Robert Rodkey
  • 423
  • 3
  • 9
  • Is there no way for meanVector to change its type to [75.575087, 60.844005, 0.145518...6.006985] instead of changing the display to the desired type? – AllThingsScience Jan 31 '16 at 04:19
  • I'm not sure what you mean by ..."meanVector to change its type" versus "...change the display to the desired type". meanVector[c].tolist() gives a type of list, but it does not alter the original object's type. – Robert Rodkey Feb 01 '16 at 15:32