2015-09-25 66 views
3

我有這樣的意甲散點圖系列:如何使用熊貓

print series.head() 
print type(series) 
print series.index 

year 
1992 36.222222 
1993 53.200000 
1994 49.400000 
1995 34.571429 
1996 39.200000 
Name: ranking, dtype: float64 
<class 'pandas.core.series.Series'> 

Int64Index([1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014], dtype='int64', name=u'year') 

我試圖做散點圖,但我無法從系列訪問索引和值。

任何指針將不勝感激。

回答

5

我相信熊貓系列不一樣,如果看T0調用.plot()上的一系列支持一種=「散」。

我相信列夫的答案是最好的,適合與熊貓一起使用。我使用matplotlib pyplot,它的工作原理與他的例子類似。

import matplotlib.pyplot as plt 
plt.scatter(ser.index, ser) 
plt.show() 

也許試試這個:

import pandas as pd 
import numpy as np 
import matplotlib.pyplot as plt 
np.random.seed(1) 

year = [1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014] 
value = np.random.rand(23) 

ser = pd.Series(index = year,data=value) 
df =ser.to_frame() 

df.reset_index(inplace=True) 
df.columns = ['year','value'] 
df.plot(kind='scatter',x='year',y='value') 
plt.show() 

enter image description here

6

是否這樣?

import pylab 
pylab.scatter(series.index, series) 
+0

忘了提,用熊貓 – oscarm

+0

這是最好的辦法,完美精緻的大熊貓。 – Dickster