2015-11-01 22 views
6

मैं एक बहुत ही आसान समस्या के साथ संघर्ष कर रहा हूं: एक पांडा डेटाफ्रेम से समय श्रृंखला रेखा चार्ट प्लॉट करने के लिए समुद्री शैवाल कैसे प्राप्त करें। मुझसे यहां क्या गलत हो रहा है?पांडा डेटाफ्रेम से समुद्री समय श्रृंखला

--------------------------------------------------------------------------- 
ValueError        Traceback (most recent call last) 
<ipython-input-306-20e252f661c2> in <module>() 
     1 df=pd.DataFrame({"Date":["2015-03-03","2015-03-02","2015-03-01"],"Close":[1,3,2]}) 
     2 df["Date"]=pd.to_datetime(df["Date"]) 
----> 3 sns.tsplot(data=df,unit=None, time="Date", value="Close") 

C:\Anaconda\lib\site-packages\seaborn\timeseries.pyc in tsplot(data, time, unit, condition, value, err_style, ci, interpolate, color, estimator, n_boot, err_palette, err_kws, legend, ax, **kwargs) 
    275  for c, (cond, df_c) in enumerate(data.groupby(condition, sort=False)): 
    276 
--> 277   df_c = df_c.pivot(unit, time, value) 
    278   x = df_c.columns.values.astype(np.float) 
    279 

C:\Anaconda\lib\site-packages\pandas\core\frame.pyc in pivot(self, index, columns, values) 
    3507   """ 
    3508   from pandas.core.reshape import pivot 
-> 3509   return pivot(self, index=index, columns=columns, values=values) 
    3510 
    3511  def stack(self, level=-1, dropna=True): 

C:\Anaconda\lib\site-packages\pandas\core\reshape.pyc in pivot(self, index, columns, values) 
    324  else: 
    325   indexed = Series(self[values].values, 
--> 326       index=MultiIndex.from_arrays([self[index], 
    327              self[columns]])) 
    328   return indexed.unstack(columns) 

C:\Anaconda\lib\site-packages\pandas\core\frame.pyc in __getitem__(self, key) 
    1795    return self._getitem_multilevel(key) 
    1796   else: 
-> 1797    return self._getitem_column(key) 
    1798 
    1799  def _getitem_column(self, key): 

C:\Anaconda\lib\site-packages\pandas\core\frame.pyc in _getitem_column(self, key) 
    1802   # get column 
    1803   if self.columns.is_unique: 
-> 1804    return self._get_item_cache(key) 
    1805 
    1806   # duplicate columns & possible reduce dimensionaility 

C:\Anaconda\lib\site-packages\pandas\core\generic.pyc in _get_item_cache(self, item) 
    1082   res = cache.get(item) 
    1083   if res is None: 
-> 1084    values = self._data.get(item) 
    1085    res = self._box_item_values(item, values) 
    1086    cache[item] = res 

C:\Anaconda\lib\site-packages\pandas\core\internals.pyc in get(self, item, fastpath) 
    2858       loc = indexer.item() 
    2859      else: 
-> 2860       raise ValueError("cannot label index with a null key") 
    2861 
    2862    return self.iget(loc, fastpath=fastpath) 

ValueError: cannot label index with a null key 

दुर्भाग्य से, मैं दस्तावेज में कोई जवाब नहीं मिला है:

import seaborn as sns 
import pandas as pd 
df=pd.DataFrame({"Date":["2015-03-03","2015-03-02","2015-03-01"],"Close":[1,3,2]}) 
df["Date"]=pd.to_datetime(df["Date"])#Not sure if seaborn can parse strings as dates 
sns.tsplot(data=df,unit=None, time="Date", value="Close") 

मैं इस ट्रैस बैक मिलता है।

उत्तर

9

समुद्री डाकू के tsplot का मतलब साधारण टाइमरीज़ लाइन प्लॉट प्लॉट करने के लिए नहीं है, लेकिन अनिश्चितताओं को साजिश करने के लिए, देखें: https://stanford.edu/~mwaskom/software/seaborn/generated/seaborn.tsplot.html

एक लाइन साजिश के लिए, आप बस

df.set_index('Date').plot() 
+4

मैं अभी भी लगता है Seaborn इस सरल मामले को कवर करना चाहिए कर सकते हैं। – fccoelho

संबंधित मुद्दे