1

The code is written in python 3.4 but I want to run it on python 3.7. I am using the Jupyter notebook to run. Can I create an environment in Jupyter and run the code in an older version of pandas(e.g. 0.16)?

--> 210             tmpvals[n] = find_non_overlapping_sample(
    211                 df.sort_index(key, ascending=phase).head(600).index, prd = no_overlap_prd)        
    212 

~\Anaconda3\lib\site-packages\pandas\core\generic.py in __getattr__(self, name)
   3079             if name in self._info_axis:
   3080                 return self[name]
-> 3081             return object.__getattribute__(self, name)
   3082 
   3083     def __setattr__(self, name, value):

AttributeError: 'DataFrame' object has no attribute 'sort' `

Even I change the sort to sort_index or sort_values. The error still exists.

Here's the function(the original code).

def gen_keydates(df, key, seasonalData=False, no_overlap_prd = 365, chatty=True):

    tmpvals={}
    if seasonalData: # For DJF data use modified function
        for n, phase in enumerate([False, True]): # Maximum, Minimum Phase
            tmpvals[n] = findNonOverlappingSeasonSample(
                df.sort(key, ascending=phase).head(600).index, key=key)
    else:
        for n, phase in enumerate([False, True]): # Maximum, Minimum Phase
            tmpvals[n] = find_non_overlapping_sample(
                df.sort(key, ascending=phase).head(600).index, prd = no_overlap_prd)        
    compPhase ={}
    compPhase['max'] = tmpvals[0][0:11].order()
    compPhase['min'] = tmpvals[1][0:11].order()
    if chatty:
        print("Average for max/min sample of {0}: {1:2.3f} and {2:2.3f}".format(
            key,np.mean(df[key][compPhase['max']]),
            np.mean(df[key][compPhase['min']])))
    return compPhase`
9
  • What is your pandas version here? Commented Oct 9, 2017 at 10:00
  • Probably the newest version, I run it on Jupyter. Is it possible to downgrade pandas to an older version on jupyter? Commented Oct 9, 2017 at 10:05
  • 4
    sort is deprecated, you should be using sort_values but you need to post code and a full description of your environment i.e. all library versions Commented Oct 9, 2017 at 10:11
  • @wongdavid It would be helpful if you could post the full error traceback here as well as pd.__version__. Commented Oct 9, 2017 at 13:50
  • 1
    Even I change the sort to sort_index or sort_values. The error still exists. are you sure you replaced all sort methods ? (in if statement AND else one)? Commented Oct 9, 2017 at 14:23

1 Answer 1

2

Sort method has been deprecated.
You should go for df.sort_values() or df.sort_index() methods.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.