【发布时间】:2013-11-05 09:52:21
【问题描述】:
我有一个昂贵的计算,在 pandas DataFrames 上运行。我想把它记下来。我正在尝试弄清楚,我可以为此使用什么。
In [16]: id(pd.DataFrame({1: [1,2,3]}))
Out[16]: 52015696
In [17]: id(pd.DataFrame({1: [1,2,3]}))
Out[17]: 52015504
In [18]: id(pd.DataFrame({1: [1,2,3]}))
Out[18]: 52015504
In [19]: id(pd.DataFrame({1: [1,2,3]})) # different results, won't work for my case
Out[19]: 52015440
In [20]: hash(pd.DataFrame({1: [1,2,3]})) # throws
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-20-3bddc0b20163> in <module>()
----> 1 hash(pd.DataFrame({1: [1,2,3]}))
/usr/local/lib/python2.7/dist-packages/pandas/core/generic.pyc in __hash__(self)
52 def __hash__(self):
53 raise TypeError('{0!r} objects are mutable, thus they cannot be'
---> 54 ' hashed'.format(self.__class__.__name__))
55
56 def __unicode__(self):
TypeError: 'DataFrame' objects are mutable, thus they cannot be hashed
鉴于我确定我不会改变被记忆的DataFrame,是否可以做我想做的事?
【问题讨论】:
标签: python pandas memoization