AttributeError: 'Series' object has no attribute 'sort_values'
Solution 1
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
Solution 2
I have got the same error recently. It's because of pandas.DataFrame.sortlevel() is deprecated since pandas version 0.20.0. Use DataFrame.sort_index() instead. This solved my problem.
Solution 3
Latest Version of Pandas has .sort_values()
import pandas as pd
pd.sort_values()
Can Be Used
Ahmet Salih Gundogdu
Updated on June 13, 2022Comments
-
Ahmet Salih Gundogdu almost 2 years
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?