Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AttributeError: 'Series' object has no attribute 'sort_values'

pyLDAvis library prepare method has crashed while using pandas library inside.

Here is the code:

    def load_R_model(filename):
        with open(filename, 'r') as j:
            data_input = json.load(j)
        data = {'topic_term_dists': data_input['phi'],
                'doc_topic_dists': data_input['theta'],
                'doc_lengths': data_input['doc.length'],
                'vocab': data_input['vocab'],
                'term_frequency': data_input['term.frequency']}
        return data

    movies_model_data = load_R_model('movie_reviews_input.json')
    print('Topic-Term shape:%s' %str(np.array(movies_model_data['topic_term_dists']).shape))
    print('Doc-Topic shape: %s' %str(np.array(movies_model_data['doc_topic_dists']).shape))

    movies_vis_data =         pyLDAvis.prepare(np.array(movies_model_data['topic_term_dists']),
                               np.array(movies_model_data['doc_topic_dists']),
                               np.array(movies_model_data['doc_lengths']),
                               np.array(movies_model_data['vocab']),
                               np.array(movies_model_data['term_frequency']))

Error:

... line 283, in prepare topic_proportion=>(topic_freq/topic_freq.sum()).sort_values(ascending=False) ...

AttributeError: 'Series' object has no attribute 'sort_values'

Why pandas has no attribute as sort_values although I updated most recent version?

like image 822
ahmetg Avatar asked Feb 09 '23 02:02

ahmetg


1 Answers

As per the documentation. http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.sort_values.html

'sort_values' is new in version 0.17.0. So, please update pandas version.

How to check pandas version:

import pandas as pd
pd.__version__

How to update pandas.

using conda: conda update pandas

using pip: pip install pandas -U

like image 73
Ayush Kesarwani Avatar answered Feb 12 '23 11:02

Ayush Kesarwani