Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Can't use pd.compare

Hey, I'm trying to use pandas method "compare", but it says that the method doesn't exist,
while I read about it at the pandas Doc: https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.Series.compare.html#pandas.Series.compare

Can anyone explain why ? Thanks!!

2 responses

@Natan Feithlicher good question. The Quantopian platform currently imports pandas version 0.18. The compare method was introduced in version 1.1.0 and therefore not available.

If you are trying to find the differences between two series, one can use the ubiquitous loc method. Maybe like this

import pandas as pd  
s1 = pd.Series(["a", "b", "c", "d", "e"])  
s2 = pd.Series(["a", "a", "c", "b", "e"])

# values in s1 which don't match s2  
s2.loc[s1 != s2]

# values in s2 which don't match s1  
s1.loc[s1 != s2]

# index values where the two series don't match (these could be the securities if that's the index)  
s1.loc[s1 != s2].index

Hope that helps.

Disclaimer

The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by Quantopian. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. No information contained herein should be regarded as a suggestion to engage in or refrain from any investment-related course of action as none of Quantopian nor any of its affiliates is undertaking to provide investment advice, act as an adviser to any plan or entity subject to the Employee Retirement Income Security Act of 1974, as amended, individual retirement account or individual retirement annuity, or give advice in a fiduciary capacity with respect to the materials presented herein. If you are an individual retirement or other investor, contact your financial advisor or other fiduciary unrelated to Quantopian about whether any given investment idea, strategy, product or service described herein may be appropriate for your circumstances. All investments involve risk, including loss of principal. Quantopian makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances.

Thank's a lot!