如何删除随附的功能号码?

时间:2016-01-31 00:54:52

标签: python numpy pandas

对于此计划如下:

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])))

我的输出是:

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

如何让输出变得简单[75.575087, 60.844005, 0.145518...6.006985] 和下一个相同?

1 个答案:

答案 0 :(得分:0)

看起来像meanVectors [c]应该返回一个具有tolist函数的Series对象。

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())))