我有一个DataFrame
和一个Series
的列。两者都有相同的DateTimeIndex
。在
我想从DataFrame
中每一行的值中减去Series
中每一行的值
以下是我的示例数据:
dates = pandas.date_range('20180101', periods=10)
stocks = ['AAPL', 'GOOG', 'MSFT', 'AMZN', 'FB']
data = numpy.random.randn(10,5)
prices = pandas.DataFrame(index=dates, columns=stocks, data=data)
returns = prices.pct_change(1)
这给了我一个DataFrame
类似于下面的
然后我创建我的Series
,这是一篮子股票的回报
这给了我一个Series
类似于下面的
现在我想从每只股票的回报中减去一篮子回报:
excess_ret = returns - basket
我收到以下警告:
RuntimeWarning: Cannot compare type 'Timestamp' with type 'str', sort order is undefined for incomparable objects return this.join(other, how=how, return_indexers=return_indexers)
这是结果DataFrame
:
这个使用在pandas-0.16.2
中工作,但我现在使用的是pandas-0.22.0
,现在似乎我无法从匹配的DataFrame
中减去Series
?在
问题:
DataFrame
中每行的所有值中减去{
我认为需要参数为} 来匹配
axis=0
的^{DataFrame
的索引Series
:如果要按列匹配:
^{pr2}$相关问题 更多 >
编程相关推荐