2015-07-10 82 views
1

我一直在用python進行數據分析的一個例子,這個例子是寶寶的名字。我生成在下面的格式的數據幀,繪製一個數據框,pandas python

1880 F  [38]  M  [14] 
1881 F  [38]  M  [14] 
1882 F  [38]  M  [15] 
1883 F  [39]  M  [15] 
1884 F  [39]  M  [16] 

我已經使用以下例程,它返回一個索引值生成此 年性。

def get_quantile_count(group, q=0.5): 
    group = group.sort_index(by='prop', ascending=False) 
    return group.prop.cumsum().searchsorted(q) + 1 

當我試圖繪製這個數據框時,我得到一個error.Are這些指數不被認爲是數值嗎?

TypeError: Empty 'DataFrame': no numeric data to plot 

回答

0

如果我沒有理解你的問題,這是解決方案的演示:

import pandas as pd 
import matplotlib as mpl 
import matplotlib.pylab as plt 
from sklearn import preprocessing 


train = pd.DataFrame([['F','1885'],['F','1884'],['F','1882'],['M','1881'],['NA','1882']],columns = ['sex','db']) 

#converting F/M/NA to integers 
le = preprocessing.LabelEncoder() 
le.fit(train['sex']) 
train['sex'] = le.transform(train['sex']) 
train = train.astype(float) 

plt.plot(train['sex'],train['db'],color='green', linestyle='dashed', marker='o', 
     markerfacecolor='blue', markersize=12) 
plt.show() 
+1

如果創建圖和座標軸的對象,你應該直接暗算的軸(即'ax.plot(TRA .. 。)') –

相關問題